-1

I'm building a web app in Flutter and I have a domain where the app is hosted. The app stores a different view for each user, like a business card, these views are public, you can access them with the domain URL and adding a hash at the end like this '/?01234567' (different hashes for each user).

This is the code for getting the hash from the URL and using it to get the user's ID from the database, for latter use.

String? getHash() {
    String? sessionHash = window.sessionStorage['hash'];
    return sessionHash;
}

Future<void> getId() async {
    print("Getting id...");

    if(m_id != 0) return; // m_id is the id of the current user view, if it is 0,
                          // then it has not been obtained from the database.

    var id = getHash(); // Gets the hash at the end of the URL

    final Uri uri = Uri.parse('${baseUrl}fetchId.php?hash=${id}');
    // 'baseUrl' is the domain's URL and inside a folder with the php files.
    // 'fetchId.php' gets the ID of the user from the database that has the same hash as the URL
    var request = http.Request('GET', uri);
    var response = await request.send(); // Send the request to get the user's ID

    if (response.statusCode == 200) { // If everything was ok
        var idStr = await response.stream.bytesToString();
        if (idStr == "") throw Exception('Failed to get ID');

        m_id = int.parse(idStr);
    }
    else {
        print("Error. Status code: ${response.statusCode}");
    }
}

The problem that I'm having is that I need to add a button that will create an icon on the user's phone home screen, which will open an app or browser to the user's page that was saved, with the correct hash.

I've tried using the install prompt to tell the user to install the app, but this saves the entire app, ignoring the hash, so the app opens either a blank page or the last user page opened on the browser.

So, is there a way to add this icon to the user's phone home screen, like a shortcut to a web page, that stores the correct hash, and most importantly, that the user can save different links to different pages of users, each in a different shortcut? And, is it possible for the user to choose the icon and name of the shortcut?

I followed this tutorial to do the install prompt: A2HS in Flutter Web

It works as it should, displays the installation message to the user and successfully installs the app on the user's phone, but it only installs the app as a whole, as the main url, forgetting the hash at the end, so when it opens, it just displays a blank page or the user's last page open in the browser.

Mascor
  • 1
  • 1

0 Answers0