Back

How to get a pref

  • 1
  • Flutter
  • Auth
  • Cloud
plushteddy
8 Sep, 2024, 17:19

Hello, how can I get user-preferences. I tried to many thing and they just don't work. I have no idea how I could convert a Preference into a string.

TL;DR
To get user preferences, use the provided function. It fetches preferences from the account, checks if the specified key is present, and returns either the value as a string or null. The issue seems to have been resolved already.
plushteddy
8 Sep, 2024, 17:30

nvm fixed

TypeScript
Future<String?> getPreference(String prefKey) async {
    try {
      Preferences prefs = await account().getPrefs();

      print(prefs.data.containsKey(prefKey) ? prefs.data[prefKey].toString() : null);
      return "done";
    } catch (e) {
      print('Fehler beim Abrufen der Präferenz: $e');
      return null;
    }
  }```


this is the solution
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more