You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
aku_new_community/lib/provider/user_provider.dart

46 lines
1.2 KiB

import 'package:akuCommunity/model/user/user_info_model.dart';
import 'package:akuCommunity/pages/sign/sign_func.dart';
4 years ago
import 'package:akuCommunity/utils/hive_store.dart';
import 'package:akuCommunity/utils/network/net_util.dart';
import 'package:flutter/material.dart';
4 years ago
class UserProvider extends ChangeNotifier {
//登录状态管理
4 years ago
bool _isSigned = false;
get isSigned => _isSigned;
4 years ago
setisSigned(bool state) {
_isSigned = state;
notifyListeners();
}
4 years ago
bool _isLogin = false;
bool get isLogin => _isLogin;
Future setLogin(int token) async {
_isLogin = true;
NetUtil().dio.options.headers.putIfAbsent('App-Admin-Token', () => token);
4 years ago
HiveStore.appBox.put('token', token);
await updateProfile();
4 years ago
notifyListeners();
}
logout() {
_isLogin = false;
_token = null;
_userInfoModel = null;
NetUtil().dio.options.headers.remove('App-Admin-Token');
4 years ago
HiveStore.appBox.delete('token');
notifyListeners();
}
Future updateProfile() async {
_userInfoModel = await SignFunc.getUserInfo();
notifyListeners();
}
4 years ago
String _token;
String get token => _token ?? '';
UserInfoModel _userInfoModel;
UserInfoModel get userInfoModel => _userInfoModel;
4 years ago
}