-1

This is the code:

class UserProvider with ChangeNotifier {
  User? _user;
  final AuthMethods _authMethods = AuthMethods();

  static User get getUser => **_user!;**

  Future<void> refreshUser() async {
    User user = await _authMethods.getUserDetails();
    _user = user;
    notifyListeners();
  }
}

I tried to call User but It had to be static so I made it static but now I have an issue with the _user!

2 Answers2

1

With prefix _ (underscore) it makes the member _user private, dart doesn't have private/public keywords.

In your case, in order to access the _user you can create a getter to access it.

You can also check the Libraries & Visibility section of dartlang.

Check more details here

Pathik Patel
  • 1,347
  • 1
  • 9
  • 22
0

You can make _user as static field, and it will be accessible on static getter.

  static int? _user;

  static int get getUser => _user!;
Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56