初始化逻辑优化

master
张萌 3 years ago
parent 700ea282a1
commit 577781cdbf

@ -30,6 +30,9 @@ class SAASAPI {
}
class _Login {
///app退
String get logOut => '/butlerApp/user/quit';
///
String get userInfo => '/butlerApp/user/findDetail';

@ -90,6 +90,7 @@ class _SetNickNamePageState extends State<SetNickNamePage> {
var result = await SignFunc.setNickName(_nickController.text);
if (result) {
await UserTool.userProvider.updateUserInfo();
SignFunc.checkNameAndAccount();
}
},
text: '确定'),

@ -93,6 +93,7 @@ class _SetPsdPageState extends State<SetPsdPage> {
await SignFunc.settingPsd(_psdController.text);
if (result) {
await UserTool.userProvider.updateUserInfo();
await SignFunc.checkNameAndAccount();
}
}
: null,

@ -2,9 +2,8 @@
import 'dart:io';
// Project imports:
import 'package:aku_new_community_manager/const/api.dart';
import 'package:aku_new_community_manager/const/saas_api.dart';
import 'package:aku_new_community_manager/new_ui/auth/sign_func.dart';
import 'package:aku_new_community_manager/saas_models/net_model/base_model.dart';
import 'package:aku_new_community_manager/saas_models/user/user_info_model.dart';
import 'package:aku_new_community_manager/utils/hive_store.dart';
@ -30,13 +29,14 @@ class UserProvider extends ChangeNotifier {
await updateUserInfo();
WebSocketUtil().setUser(_userInfoModel!.id.toString());
WebSocketUtil().startWebSocket();
await SignFunc.checkNameAndAccount();
}
notifyListeners();
}
///
logout() async {
await NetUtil().get(API.auth.logout, showMessage: true);
await NetUtil().get(SAASAPI.login.logOut, showMessage: true);
WebSocketUtil().closeWebSocket();
NetUtil().logout();
_isLogin = false;
@ -88,6 +88,7 @@ class UserProvider extends ChangeNotifier {
if (model.success) {
await updateUserInfo();
}
notifyListeners();
}
Future updateUserInfo() async {

@ -4,10 +4,14 @@ import 'package:aku_new_community_manager/new_ui/auth/login_root_page.dart';
import 'package:aku_new_community_manager/provider/app_provider.dart';
import 'package:aku_new_community_manager/provider/user_provider.dart';
import 'package:aku_new_community_manager/style/app_style.dart';
import 'package:aku_new_community_manager/tools/user_tool.dart';
import 'package:aku_new_community_manager/ui/agreements/agreement_page.dart';
import 'package:aku_new_community_manager/ui/agreements/privacy_page.dart';
import 'package:aku_new_community_manager/utils/dev_util.dart';
import 'package:aku_new_community_manager/utils/hive_store.dart';
import 'package:aku_new_community_manager/utils/websocket/fier_dialog.dart';
import 'package:aku_new_community_manager/utils/websocket/web_socket_util.dart';
import 'package:equatable/equatable.dart';
// Package imports:
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
@ -39,20 +43,6 @@ class _SplashPageState extends State<SplashPage> {
// };
// }
Future _initOp() async {
final userProvider = Provider.of<UserProvider>(context, listen: false);
if (HiveStore.appBox!.containsKey('token')) {
await userProvider.setLogin(HiveStore.appBox!.get('token'));
} else {
Get.to(() => LoginPage());
}
//AMap
// await AmapLocation.instance.init(iosKey: 'ios key');
await Permission.locationWhenInUse.request();
final appProvider = Provider.of<AppProvider>(context, listen: false);
appProvider.startLocation();
}
Future<bool?> _showLoginVerify() async {
return await showCupertinoDialog(
barrierDismissible: false,
@ -109,6 +99,8 @@ class _SplashPageState extends State<SplashPage> {
//HiveStore
await Hive.initFlutter();
await HiveStore.init();
///
var agreement = false;
if (HiveStore.appBox!.containsKey('agreement')) {
agreement = await HiveStore.appBox!.get('agreement');
@ -123,7 +115,36 @@ class _SplashPageState extends State<SplashPage> {
}
}
if (mounted) PowerLogger.start(context, debug: DevUtil.isDev);
await _initOp();
///
EquatableConfig.stringify = true;
// AMapFlutterLocation.updatePrivacyShow(true, true);
// AMapFlutterLocation.updatePrivacyAgree(true);
WebSocketUtil().initWebSocket(
consolePrint: false,
onReceiveMes: (message) async {
await FireDialog.fireAlert(message);
},
onError: (e) {
LoggerData.addData(e);
},
);
///
await Permission.locationWhenInUse.request();
final appProvider = Provider.of<AppProvider>(context, listen: false);
appProvider.startLocation();
///
await UserTool.dataProvider.init();
///
final userProvider = Provider.of<UserProvider>(context, listen: false);
if (HiveStore.appBox!.containsKey('token')) {
await userProvider.setLogin(HiveStore.appBox!.get('token'));
} else {
Get.to(() => LoginPage());
}
});
}

Loading…
Cancel
Save