userId property

Future<String> userId

Generate a user id that is;

  • unique
  • anonymous
  • persistent

This id is generated the first time this method is called and then stored on the phone in-between sessions, and will therefore be the same for the same app on the same phone.

Implementation

Future<String> get userId async {
  assert(_preferences != null,
      "Setting is not initialized. Call 'Setting().init()' first.");
  if (_userId == null) {
    _userId = preferences!.get(USER_ID_KEY) as String?;
    if (_userId == null) {
      _userId = Uuid().v1();
      await preferences!.setString(USER_ID_KEY, _userId!);
    }
  }
  return _userId!;
}