| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- // 提供五套可选主题色
- import 'dart:convert';
- import 'package:e2ee_chat/common/profile.dart';
- import 'package:e2ee_chat/network/api.dart';
- import 'package:e2ee_chat/models/user_model.dart';
- import 'package:flutter/material.dart';
- import 'package:shared_preferences/shared_preferences.dart';
- const _themes = <MaterialColor>[
- Colors.blue,
- Colors.cyan,
- Colors.teal,
- Colors.green,
- Colors.red,
- ];
- class Global {
- static Profile profile = Profile();
- // 可选的主题列表
- static List<MaterialColor> get themes => _themes;
- // 是否为release版
- static bool get isRelease => bool.fromEnvironment("dart.vm.product");
- static final String emptyToken = "token";
- //初始化全局信息,会在APP启动时执行
- static init() async {
- var _prefs = await SharedPreferences.getInstance();
- var _profile = _prefs.getString("profile");
- if (_profile != null) {
- try {
- profile = Profile.fromJson(jsonDecode(_profile));
- profile.isLogin = false;
- } catch (e) {
- print(e);
- }
- }
- await Api.init();
- UserModel().login();
- }
- // 持久化Profile信息
- static saveProfile() async {
- var _prefs = await SharedPreferences.getInstance();
- _prefs.setString("profile", jsonEncode(profile.toJson()));
- }
- }
|