用户配置本地存贮

hmxc
张萌 3 years ago
parent f0fd7260b1
commit d212f4018c

@ -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<String, dynamic> json) =>
_$UserConfigModelFromJson(json);
UserConfigModel({
required this.userId,
required this.clockRemind,
required this.todayClocked,
});
}

@ -0,0 +1,58 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'user_config_model.dart';
// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************
class UserConfigModelAdapter extends TypeAdapter<UserConfigModel> {
@override
final int typeId = 5;
@override
UserConfigModel read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
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<String, dynamic> json) =>
UserConfigModel(
userId: json['userId'] as int,
clockRemind: json['clockRemind'] as bool,
todayClocked: json['todayClocked'] as bool,
);

@ -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/progress_paint.dart';
import 'package:aku_new_community/pages/personal/intergral/rule_explain_page.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/bee_back_button.dart';
import 'package:aku_new_community/widget/others/user_tool.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
@ -205,6 +206,9 @@ class _integralCenterPageState extends State<integralCenterPage> {
Positioned( Positioned(
right: 0, right: 0,
top: 168.w, top: 168.w,
child: GestureDetector(
onTap: (){
},
child: Container( child: Container(
width: 176.w, width: 176.w,
height: 58.w, height: 58.w,
@ -218,6 +222,7 @@ class _integralCenterPageState extends State<integralCenterPage> {
'购物得活跃度'.text.size(24.sp).color(Color(0xFFFE905A)).make(), '购物得活跃度'.text.size(24.sp).color(Color(0xFFFE905A)).make(),
), ),
), ),
),
], ],
), ),
), ),

@ -335,6 +335,8 @@ class _PersonalIndexState extends State<PersonalIndex>
onPressed: () async { onPressed: () async {
await Get.dialog(ClockSuccessDialog( await Get.dialog(ClockSuccessDialog(
todayIntegral: 1, tomorrowIntegral: 2)); todayIntegral: 1, tomorrowIntegral: 2));
await UserTool.userProvider
.changeTodayClocked();
}, },
elevation: 0, elevation: 0,
color: Colors.white, color: Colors.white,
@ -342,7 +344,12 @@ class _PersonalIndexState extends State<PersonalIndex>
height: 58.w, height: 58.w,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50.w)), 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, 32.w.widthBox,
], ],

@ -2,6 +2,7 @@ import 'dart:io';
import 'package:aku_new_community/constants/api.dart'; import 'package:aku_new_community/constants/api.dart';
import 'package:aku_new_community/model/user/user_detail_model.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/models/user/user_info_model.dart';
import 'package:aku_new_community/pages/sign/sign_func.dart'; import 'package:aku_new_community/pages/sign/sign_func.dart';
import 'package:aku_new_community/provider/app_provider.dart'; import 'package:aku_new_community/provider/app_provider.dart';
@ -38,6 +39,13 @@ class UserProvider extends ChangeNotifier {
HiveStore.appBox!.put('login', true); HiveStore.appBox!.put('login', true);
await updateProfile(); await updateProfile();
await updateUserDetail(); await updateUserDetail();
///
_userConfig = await HiveStore.userBox!.get('${_userInfoModel!.id}') ??
UserConfigModel(
userId: _userInfoModel!.id,
clockRemind: false,
todayClocked: false);
await appProvider.updateHouses(await HouseFunc.passedHouses); await appProvider.updateHouses(await HouseFunc.passedHouses);
if (isLogin) { if (isLogin) {
WebSocketUtil().setUser(userInfoModel!.id.toString()); WebSocketUtil().setUser(userInfoModel!.id.toString());
@ -161,4 +169,25 @@ class UserProvider extends ChangeNotifier {
await updateProfile(); 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);
}
} }

@ -1,6 +1,7 @@
import 'package:aku_new_community/model/user/province_model.dart'; 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/china_region_model.dart';
import 'package:aku_new_community/models/login/history_login_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:flutter/foundation.dart';
import 'package:hive/hive.dart'; import 'package:hive/hive.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
@ -11,6 +12,8 @@ class HiveStore {
static Box? get appBox => _appBox; static Box? get appBox => _appBox;
static Box? _chinaRegionBox; static Box? _chinaRegionBox;
static Box? get chinaRegionBox => _chinaRegionBox; static Box? get chinaRegionBox => _chinaRegionBox;
static Box? _userBox;
static Box? get userBox => _userBox;
static Future init() async { static Future init() async {
if (!kIsWeb) { if (!kIsWeb) {
@ -21,8 +24,10 @@ class HiveStore {
Hive.registerAdapter(DistrictAdapter()); Hive.registerAdapter(DistrictAdapter());
Hive.registerAdapter(ChinaRegionModelAdapter()); Hive.registerAdapter(ChinaRegionModelAdapter());
Hive.registerAdapter(HistoryLoginModelAdapter()); Hive.registerAdapter(HistoryLoginModelAdapter());
Hive.registerAdapter(UserConfigModelAdapter());
_appBox = await Hive.openBox('app'); _appBox = await Hive.openBox('app');
_chinaRegionBox = await Hive.openBox('chinaRegionBox'); _chinaRegionBox = await Hive.openBox('chinaRegionBox');
_userBox = await Hive.openBox('userBox');
} }
} }
} }

Loading…
Cancel
Save