| 123456789101112131415161718192021222324252627282930313233343536 |
- import 'package:flutter_secure_storage/flutter_secure_storage.dart';
- import 'package:json_annotation/json_annotation.dart';
- import 'package:e2ee_chat/common/global.dart';
- part 'Profile.g.dart';
- @JsonSerializable()
- class Profile {
- Profile();
- factory Profile.fromJson(Map<String, dynamic> json) => _$ProfileFromJson(json);
- Map<String, dynamic> toJson() => _$ProfileToJson(json);
- int theme = Global.themes[0].value;
- String? username;
- bool isLogin = false;
- String locale = "zh";
- String? get token {
- if (username == null) return null;
- final storage = FlutterSecureStorage();
- String? token;
- storage.read(key: _tokenKey).then((v) => token = v);
- return token;
- }
- set token(String? token) {
- assert(username != null, "username == null when setting token");
- final storage = FlutterSecureStorage();
- storage.write(key: _tokenKey, value: token);
- }
- String get _tokenKey => "e2ee_chat token of $username";
- }
|