Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

空安全问题? #26

Open
YuQi9797 opened this issue Jul 19, 2023 · 2 comments
Open

空安全问题? #26

YuQi9797 opened this issue Jul 19, 2023 · 2 comments

Comments

@YuQi9797
Copy link

大佬您好,关于此处: User get user => _profile.user;
由于_profile.userUser? 类型的, 所以在get的返回类型中改为了 User?
但当改好后User? get user => _profile.user; 又出现问题提示:The return type of getter 'user' is 'User?' which isn't a subtype of the type 'User' of its setter 'user'.

请问这种该如何解决呢? 谢谢!

@YuQi9797
Copy link
Author

这样吗?

class UserModel extends ProfileChangeNotifier {
  User? get user => _profile.user;

  // APP是否登录(如果有用户信息,则证明登录过)
  bool get isLogin => user != null;

  // 用户信息发生变化,更新用户信息并通知依赖它的子孙Widgets更新
  set user(User? user) {
    if (user?.login != _profile.user?.login) {
      _profile.lastLogin = _profile.user?.login;
      _profile.user = user;
      notifyListeners();
    }
  }
}

@liwei118
Copy link

liwei118 commented Dec 7, 2024

Is the problem solved?
I changed the judgment that controls security, but there are new problems in my code.

error: The return type of getter 'user' is 'User?' which isn't a subtype of the type 'User' of its setter 'user'.

class UserModel extends ProfileChangeNotifier {
  User? get user => _profile.user;

  // APP是否登录(如果有用户信息,则证明登录过)
  bool get isLogin => user != null;

  //用户信息发生变化,更新用户信息并通知依赖它的子孙Widgets更新
  set user(User user) {
    if (user?.login != _profile.user?.login) {
      _profile.lastLogin = _profile.user?.login;
      _profile.user = user;
      notifyListeners();
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants