主要四个页面的基础页面
This commit is contained in:
@@ -1,11 +1,46 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:get_storage/get_storage.dart';
|
||||
|
||||
class AuthService extends GetxService {
|
||||
static AuthService get to => Get.find<AuthService>();
|
||||
|
||||
final _box = GetStorage();
|
||||
|
||||
/// 供外部使用的,判断是否登录的状态
|
||||
get isUserLogin => isLogin.value;
|
||||
|
||||
/// 登录状态记录,可监听的,这样ever才能监听到
|
||||
final RxBool isLogin = false.obs;
|
||||
|
||||
/// 登录的token,供请求时调用,载入内存,是为了每次使用的时候,不需要从磁盘获取
|
||||
late String userToken = '';
|
||||
|
||||
/// 获取存储的token,这个可以做到持久化存储
|
||||
String get _userToken => _box.read('userToken') ?? '';
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
|
||||
if (_userToken.isNotEmpty) {
|
||||
isLogin.value = true;
|
||||
userToken = _userToken;
|
||||
}
|
||||
|
||||
// ever(_isLogin, (_) {
|
||||
// if (_ == true) {
|
||||
// Get.offAllNamed(AppRoutes.app);
|
||||
// } else {
|
||||
// Get.offAllNamed(AuthRoutes.index);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
Future<bool> login(String address) async {
|
||||
_box.write('userToken', address);
|
||||
userToken = address;
|
||||
isLogin.value = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user