| | |
| | | import 'dart:async'; |
| | | import 'dart:convert'; |
| | | import 'dart:ui'; |
| | | |
| | | import 'package:flutter/cupertino.dart'; |
| | | import 'package:flutter/services.dart'; |
| | | import 'package:fluwx_no_pay/fluwx_no_pay.dart' as fluwx; |
| | | import 'package:locations/api/http.dart'; |
| | | import 'package:locations/model/user/user_info.dart'; |
| | | import 'package:locations/utils/event_bus_util.dart'; |
| | | import 'package:locations/utils/location_util.dart'; |
| | | import 'package:locations/utils/string_util.dart'; |
| | | import 'package:shared_preferences/shared_preferences.dart'; |
| | | |
| | | import 'push_util.dart'; |
| | | |
| | | Timer? locationTimer; |
| | | |
| | | class UserUtil { |
| | | static const _loginMessageChannel = |
| | |
| | | } |
| | | } |
| | | |
| | | static Future updateUserInfo(BuildContext context) async { |
| | | int? uid = await getUid(); |
| | | if (uid == null) { |
| | | return; |
| | | } |
| | | |
| | | Map<String, dynamic>? result = await UserApiUtil.getUserInfo(context, uid); |
| | | var code = result!["code"]; |
| | | if (code == 0) { |
| | | UserInfo user = UserInfo.fromJson(result["data"]); |
| | | //保存用户信息 |
| | | UserUtil.setUserInfo(user); |
| | | //是否启动定位 |
| | | |
| | | locationTimer ??= Timer(Duration(seconds: 30), () { |
| | | //判断是否已经登录 |
| | | getUid().then((value) { |
| | | if (value == null) { |
| | | return; |
| | | } |
| | | if (user.needAlwaysLocation!) { |
| | | LocationUtil.startLocation(30, (state, map) {}); |
| | | } |
| | | }); |
| | | }); |
| | | } else if (code == 80001 || code == 80002) { |
| | | await logout(); |
| | | } |
| | | } |
| | | |
| | | static Future<int?> getUid() async { |
| | | UserInfo? user = await getUserInfo(); |
| | | if (user != null) { |
| | |
| | | |
| | | //退出登录 |
| | | static logout() async { |
| | | await _logout(); |
| | | await PushUtil.removeAlias(); |
| | | eventBus.fire(LoginEventBus(false)); |
| | | } |
| | | |
| | | static _logout() async { |
| | | SharedPreferences prefs = await SharedPreferences.getInstance(); |
| | | prefs.remove("user_info"); |
| | | } |