部分登录
This commit is contained in:
@@ -1,10 +1,57 @@
|
||||
import 'package:cashier_reserve/login/login_view.dart';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../base/ui.dart';
|
||||
import '../channel/channel_event.dart';
|
||||
import '../utils/func_tools.dart';
|
||||
import 'hive_manager.dart';
|
||||
|
||||
class AppManager {
|
||||
static BuildContext? globalContext;
|
||||
static bool _isAlertLogin = false;
|
||||
|
||||
static Future<void> initThirdPackage() async {
|
||||
MyEventChannel.startListener();
|
||||
|
||||
await HiveManager.initHive();
|
||||
}
|
||||
}
|
||||
|
||||
static void setGlobalContext(BuildContext context) {
|
||||
globalContext = context;
|
||||
}
|
||||
|
||||
static bool isLogin() {
|
||||
String token = HiveManager.getUserToken();
|
||||
if (isEmptyString(token)) {
|
||||
gotoLogin();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void gotoLogin() {
|
||||
if (_isAlertLogin) {
|
||||
return;
|
||||
}
|
||||
_isAlertLogin = true;
|
||||
|
||||
while (Navigator.of(globalContext!).canPop()) {
|
||||
Navigator.of(globalContext!).pop();
|
||||
}
|
||||
|
||||
showDialog(
|
||||
context: globalContext!,
|
||||
barrierDismissible: false,
|
||||
builder: (BuildContext context) {
|
||||
return WillPopScope(
|
||||
onWillPop: () => Future.value(false), child: const LoginView());
|
||||
});
|
||||
}
|
||||
|
||||
static void disposeLoginWidget() {
|
||||
_isAlertLogin = false;
|
||||
}
|
||||
|
||||
static bool isShowLoginView() {
|
||||
return _isAlertLogin;
|
||||
}
|
||||
}
|
||||
|
||||
17
lib/common/manager/hive_manager.dart
Normal file
17
lib/common/manager/hive_manager.dart
Normal file
@@ -0,0 +1,17 @@
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
class HiveManager {
|
||||
static Box? _userInfoBox;
|
||||
|
||||
static Future<void> initHive() async {
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
Hive.defaultDirectory = dir.path;
|
||||
|
||||
_userInfoBox = Hive.box();
|
||||
}
|
||||
|
||||
static String getUserToken() {
|
||||
return _userInfoBox?.get('token') ?? '';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user