Open YuQi9797 opened 1 year ago
这样吗?
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();
}
}
}
https://github.com/wendux/flutter_in_action_source_code/blob/e5e54b3082bc344fb9c236a9e24796ac568ac859/github_client_app/lib/states/profile_change_notifier.dart#L14
大佬您好,关于此处:
User get user => _profile.user;
由于_profile.user
是User?
类型的, 所以在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'.请问这种该如何解决呢? 谢谢!