登录流程已全部重构

This commit is contained in:
zhutao
2025-09-23 11:47:29 +08:00
parent a4992a063b
commit 8988b3feea
71 changed files with 2036 additions and 901 deletions

46
lib/stores/app_store.dart Normal file
View File

@@ -0,0 +1,46 @@
import 'package:food_health/api/dto/login_dto.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../data/local/storage.dart';
class AppStore with ChangeNotifier {
///用户信息
UserInfo? userInfo;
///token
String token = '';
//初始化
Future<void> init() async {
token = await getToken();
var userInfoStorage = await Storage.get('userInfo');
if (userInfoStorage != null) {
userInfo = UserInfo.fromJson(await Storage.get('userInfo'));
}
notifyListeners();
}
///设置用户数据
Future<void> setInfo(LoginDto data) async {
token = data.accessToken!;
userInfo = data.userInfo;
await Storage.set('userInfo', userInfo?.toJson());
await Storage.set('token', token);
}
///获取token
static Future<String> getToken() async {
return await Storage.get("token") ?? '';
}
///退出登录
Future<void> logout() async {
await Storage.remove('token');
await Storage.remove('userInfo');
token = '';
userInfo = null;
notifyListeners();
}
}

View File

@@ -0,0 +1,20 @@
import 'dart:ui';
import 'package:flutter/cupertino.dart';
class SettingStore extends ChangeNotifier {
late Locale _locale;
Locale get locale => _locale;
SettingStore() {
final systemLocale = PlatformDispatcher.instance.locale;
_locale = systemLocale;
}
/// 设置语言
void setLocale(Locale locale) {
_locale = locale;
notifyListeners();
}
}

View File

@@ -0,0 +1,14 @@
import 'package:flutter/cupertino.dart';
import 'package:food_health/api/dto/user_profile_dto.dart';
import 'package:food_health/api/endpoints/profile_api.dart';
class UserStore with ChangeNotifier {
UserProfileDto profile = UserProfileDto();
//初始化数据
Future<void> init() async {
var res = await getUserProfileApi();
profile = res;
notifyListeners();
}
}