80 lines
1.9 KiB
Dart
80 lines
1.9 KiB
Dart
import 'package:cashier_reserve/common/push/push.dart';
|
|
import 'package:cashier_reserve/data_model/login/login_result.dart';
|
|
import 'package:cashier_reserve/login/login_view.dart';
|
|
import 'package:cashier_reserve/model/reserve_model.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 String _smsContent = "";
|
|
|
|
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();
|
|
}
|
|
|
|
YJPush.presentWidget(globalContext!, const LoginView());
|
|
}
|
|
|
|
static void disposeLoginWidget() {
|
|
_isAlertLogin = false;
|
|
}
|
|
|
|
static bool isShowLoginView() {
|
|
return _isAlertLogin;
|
|
}
|
|
|
|
static String getUserToken() {
|
|
return HiveManager.getUserToken();
|
|
}
|
|
|
|
static void loginSuccess(LoginResult? r) {
|
|
HiveManager.setUserToken(r?.token ?? '');
|
|
HiveManager.setShopId((r?.shopId ?? '').toString());
|
|
HiveManager.setShopName(r?.shopName ?? '');
|
|
HiveManager.setShopLogo(r?.logo ?? '');
|
|
HiveManager.setUserInfo(r?.user?.toString() ?? '');
|
|
|
|
disposeLoginWidget();
|
|
Navigator.of(globalContext!).pop();
|
|
}
|
|
|
|
static Future<String> loadReserveSms() async {
|
|
if (_smsContent.isNotEmpty) {
|
|
return _smsContent;
|
|
}
|
|
_smsContent = await ReserveModel.getReserveSms();
|
|
return _smsContent;
|
|
}
|
|
}
|