user_config.dart 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // 用户相关的操作状态 State 类,用于 RiverPod 中 Provider 的定义
  2. import 'package:domain/entity/user_me_entity.dart';
  3. class UserConfig {
  4. //用户的详情信息
  5. UserMeEntity? user;
  6. //用户的登录Token
  7. String? token;
  8. //用户姓名
  9. String? userName;
  10. //用户是否已经登录
  11. bool hasLogin = false;
  12. //用户的 registrationId 推送标识
  13. String? registrationId;
  14. //用户的未读消息数量
  15. int unreadNotificationsCount = 0;
  16. /// 获取用户默认的房产名称
  17. String? getDefaultEstateName() {
  18. return user?.estates
  19. ?.firstWhere(
  20. (estate) => estate.accounts?.any((a) => a.isDefault == 1) ?? false,
  21. orElse: () => UserMeEstates(), // 如果没有匹配项返回 null name
  22. )
  23. .name;
  24. }
  25. /// =================================== 插件自动生成-无需手动修改 ↓ ===================================
  26. //<editor-fold desc="Data Methods">
  27. UserConfig({
  28. this.user,
  29. this.token,
  30. this.userName,
  31. required this.hasLogin,
  32. this.registrationId,
  33. required this.unreadNotificationsCount,
  34. });
  35. UserConfig copyWith({
  36. UserMeEntity? user,
  37. String? token,
  38. String? userName,
  39. bool? hasLogin,
  40. String? registrationId,
  41. int? unreadNotificationsCount,
  42. }) {
  43. return UserConfig(
  44. user: user ?? this.user,
  45. token: token ?? this.token,
  46. userName: userName ?? this.userName,
  47. hasLogin: hasLogin ?? this.hasLogin,
  48. registrationId: registrationId ?? this.registrationId,
  49. unreadNotificationsCount: unreadNotificationsCount ?? this.unreadNotificationsCount,
  50. );
  51. }
  52. //</editor-fold>
  53. }