主要四个页面的基础页面

This commit is contained in:
2022-10-19 17:47:04 +08:00
parent 2ddccb3f9d
commit 49ad269c2b
13 changed files with 156 additions and 74 deletions

View File

@@ -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;
}
}