diff --git a/lib/models/user/user_config_model.dart b/lib/models/user/user_config_model.dart new file mode 100644 index 00000000..0f7652d1 --- /dev/null +++ b/lib/models/user/user_config_model.dart @@ -0,0 +1,22 @@ +import 'package:hive/hive.dart'; +import 'package:json_annotation/json_annotation.dart'; + +part 'user_config_model.g.dart'; + +@JsonSerializable() +@HiveType(typeId: 5) +class UserConfigModel { + @HiveField(0) + int userId; + @HiveField(1) + bool clockRemind; + @HiveField(2) + bool todayClocked; + factory UserConfigModel.fromJson(Map json) => + _$UserConfigModelFromJson(json); + UserConfigModel({ + required this.userId, + required this.clockRemind, + required this.todayClocked, + }); +} diff --git a/lib/models/user/user_config_model.g.dart b/lib/models/user/user_config_model.g.dart new file mode 100644 index 00000000..9cdbafd2 --- /dev/null +++ b/lib/models/user/user_config_model.g.dart @@ -0,0 +1,58 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'user_config_model.dart'; + +// ************************************************************************** +// TypeAdapterGenerator +// ************************************************************************** + +class UserConfigModelAdapter extends TypeAdapter { + @override + final int typeId = 5; + + @override + UserConfigModel read(BinaryReader reader) { + final numOfFields = reader.readByte(); + final fields = { + for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), + }; + return UserConfigModel( + userId: fields[0] as int, + clockRemind: fields[1] as bool, + todayClocked: fields[2] as bool, + ); + } + + @override + void write(BinaryWriter writer, UserConfigModel obj) { + writer + ..writeByte(3) + ..writeByte(0) + ..write(obj.userId) + ..writeByte(1) + ..write(obj.clockRemind) + ..writeByte(2) + ..write(obj.todayClocked); + } + + @override + int get hashCode => typeId.hashCode; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is UserConfigModelAdapter && + runtimeType == other.runtimeType && + typeId == other.typeId; +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +UserConfigModel _$UserConfigModelFromJson(Map json) => + UserConfigModel( + userId: json['userId'] as int, + clockRemind: json['clockRemind'] as bool, + todayClocked: json['todayClocked'] as bool, + ); diff --git a/lib/pages/personal/intergral/integral_center_page.dart b/lib/pages/personal/intergral/integral_center_page.dart index b96e99b3..d9ee3b3e 100644 --- a/lib/pages/personal/intergral/integral_center_page.dart +++ b/lib/pages/personal/intergral/integral_center_page.dart @@ -2,6 +2,7 @@ import 'package:aku_new_community/gen/assets.gen.dart'; import 'package:aku_new_community/pages/personal/intergral/progress_paint.dart'; import 'package:aku_new_community/pages/personal/intergral/rule_explain_page.dart'; import 'package:aku_new_community/widget/bee_back_button.dart'; +import 'package:aku_new_community/widget/others/user_tool.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -205,17 +206,21 @@ class _integralCenterPageState extends State { Positioned( right: 0, top: 168.w, - child: Container( - width: 176.w, - height: 58.w, - decoration: BoxDecoration( - color: Color(0xFFFFF7E1), - borderRadius: BorderRadius.only( - topLeft: Radius.circular(29.w), - bottomLeft: Radius.circular(29.w))), - alignment: Alignment.center, - child: - '购物得活跃度'.text.size(24.sp).color(Color(0xFFFE905A)).make(), + child: GestureDetector( + onTap: (){ + }, + child: Container( + width: 176.w, + height: 58.w, + decoration: BoxDecoration( + color: Color(0xFFFFF7E1), + borderRadius: BorderRadius.only( + topLeft: Radius.circular(29.w), + bottomLeft: Radius.circular(29.w))), + alignment: Alignment.center, + child: + '购物得活跃度'.text.size(24.sp).color(Color(0xFFFE905A)).make(), + ), ), ), ], diff --git a/lib/pages/personal/personal_page.dart b/lib/pages/personal/personal_page.dart index fc4ff925..c7160ed8 100644 --- a/lib/pages/personal/personal_page.dart +++ b/lib/pages/personal/personal_page.dart @@ -335,6 +335,8 @@ class _PersonalIndexState extends State onPressed: () async { await Get.dialog(ClockSuccessDialog( todayIntegral: 1, tomorrowIntegral: 2)); + await UserTool.userProvider + .changeTodayClocked(); }, elevation: 0, color: Colors.white, @@ -342,7 +344,12 @@ class _PersonalIndexState extends State height: 58.w, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(50.w)), - child: '签到'.text.size(22.sp).black.make(), + child: + '${UserTool.userProvider.userConfig.todayClocked ? '已签到' : '签到'}' + .text + .size(22.sp) + .black + .make(), ), 32.w.widthBox, ], diff --git a/lib/provider/user_provider.dart b/lib/provider/user_provider.dart index 95471e90..65cc88e9 100644 --- a/lib/provider/user_provider.dart +++ b/lib/provider/user_provider.dart @@ -2,6 +2,7 @@ import 'dart:io'; import 'package:aku_new_community/constants/api.dart'; import 'package:aku_new_community/model/user/user_detail_model.dart'; +import 'package:aku_new_community/models/user/user_config_model.dart'; import 'package:aku_new_community/models/user/user_info_model.dart'; import 'package:aku_new_community/pages/sign/sign_func.dart'; import 'package:aku_new_community/provider/app_provider.dart'; @@ -38,6 +39,13 @@ class UserProvider extends ChangeNotifier { HiveStore.appBox!.put('login', true); await updateProfile(); await updateUserDetail(); + + ///初始化用户配置 + _userConfig = await HiveStore.userBox!.get('${_userInfoModel!.id}') ?? + UserConfigModel( + userId: _userInfoModel!.id, + clockRemind: false, + todayClocked: false); await appProvider.updateHouses(await HouseFunc.passedHouses); if (isLogin) { WebSocketUtil().setUser(userInfoModel!.id.toString()); @@ -161,4 +169,25 @@ class UserProvider extends ChangeNotifier { await updateProfile(); } } + + UserConfigModel _userConfig = + UserConfigModel(userId: 0, clockRemind: false, todayClocked: false); + + UserConfigModel get userConfig => _userConfig; + + Future changeClockRemind() async { + _userConfig.clockRemind = !_userConfig.clockRemind; + await updateUserConfig(); + notifyListeners(); + } + + Future changeTodayClocked() async { + _userConfig.todayClocked = true; + await updateUserConfig(); + notifyListeners(); + } + + Future updateUserConfig() async { + HiveStore.userBox!.put('${_userConfig.userId}', _userConfig); + } } diff --git a/lib/utils/hive_store.dart b/lib/utils/hive_store.dart index a50a50b7..13335cb4 100644 --- a/lib/utils/hive_store.dart +++ b/lib/utils/hive_store.dart @@ -1,6 +1,7 @@ import 'package:aku_new_community/model/user/province_model.dart'; import 'package:aku_new_community/models/login/china_region_model.dart'; import 'package:aku_new_community/models/login/history_login_model.dart'; +import 'package:aku_new_community/models/user/user_config_model.dart'; import 'package:flutter/foundation.dart'; import 'package:hive/hive.dart'; import 'package:path_provider/path_provider.dart'; @@ -11,6 +12,8 @@ class HiveStore { static Box? get appBox => _appBox; static Box? _chinaRegionBox; static Box? get chinaRegionBox => _chinaRegionBox; + static Box? _userBox; + static Box? get userBox => _userBox; static Future init() async { if (!kIsWeb) { @@ -21,8 +24,10 @@ class HiveStore { Hive.registerAdapter(DistrictAdapter()); Hive.registerAdapter(ChinaRegionModelAdapter()); Hive.registerAdapter(HistoryLoginModelAdapter()); + Hive.registerAdapter(UserConfigModelAdapter()); _appBox = await Hive.openBox('app'); _chinaRegionBox = await Hive.openBox('chinaRegionBox'); + _userBox = await Hive.openBox('userBox'); } } }