feat:更新个人主页模块
This commit is contained in:
28
lib/provider/user_provider.dart
Normal file
28
lib/provider/user_provider.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:food_hub_app/apis/user.dart';
|
||||
import 'package:food_hub_app/models/session.dart';
|
||||
|
||||
class UserProvider with ChangeNotifier {
|
||||
late User currentUser = User.getEmpty();
|
||||
bool isLoading = false;
|
||||
String error = '';
|
||||
|
||||
Future<void> refreshUser(int id) async {
|
||||
if (isLoading) return;
|
||||
|
||||
try {
|
||||
isLoading = true;
|
||||
error = '';
|
||||
notifyListeners();
|
||||
|
||||
final result = await queryUserApi(id);
|
||||
currentUser = result;
|
||||
} catch (e) {
|
||||
error = '加载数据失败: $e';
|
||||
debugPrint('加载数据失败: $e');
|
||||
} finally {
|
||||
isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user