| | |
| | | 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/model/user/user_info.dart'; |
| | | import 'package:locations/utils/string_util.dart'; |
| | | import 'package:shared_preferences/shared_preferences.dart'; |
| | | |
| | | class UserUtil { |
| | | static const _loginMessageChannel = |
| | | const BasicMessageChannel('ThirdLogin', StandardMessageCodec()); |
| | | BasicMessageChannel('ThirdLogin', StandardMessageCodec()); |
| | | |
| | | //是否同意了用户协议 |
| | | static Future<bool> isAgreeProtocol() async { |
| | |
| | | .then((value) {}); |
| | | } |
| | | |
| | | ///QQ登录 |
| | | static Future<Map> loginQQ() async { |
| | | Map value = await _loginMessageChannel.send({"method": "loginQQ"}) as Map; |
| | | return value; |
| | | } |
| | | |
| | | //是否已经登录 |
| | | static Future<bool> isLogin() async { |
| | | UserInfo? user = await getUserInfo(); |
| | | return user != null; |
| | | } |
| | | |
| | | //用户信息 |
| | | static Future<UserInfo?> getUserInfo() async { |
| | | SharedPreferences prefs = await SharedPreferences.getInstance(); |
| | | String? result = await prefs.getString("user_info"); |
| | | if (StringUtil.isNullOrEmpty(result)) { |
| | | return null; |
| | | } else { |
| | | return UserInfo.fromJson(jsonDecode(result!)); |
| | | } |
| | | } |
| | | |
| | | static Future<int?> getUid() async { |
| | | UserInfo? user = await getUserInfo(); |
| | | if (user != null) { |
| | | return user.id; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | static Future setUserInfo(UserInfo user) async { |
| | | SharedPreferences prefs = await SharedPreferences.getInstance(); |
| | | await prefs.setString("user_info", jsonEncode(user)); |
| | | } |
| | | |
| | | //退出登录 |
| | | static logout() async { |
| | | SharedPreferences prefs = await SharedPreferences.getInstance(); |
| | | prefs.remove("user_info"); |
| | | } |
| | | } |