diff --git a/assets/images/empty.png b/assets/images/empty.png new file mode 100644 index 0000000..4511838 Binary files /dev/null and b/assets/images/empty.png differ diff --git a/lib/models/auth/auth_model.dart b/lib/models/auth/auth_model.dart index 4f94dc7..a550862 100644 --- a/lib/models/auth/auth_model.dart +++ b/lib/models/auth/auth_model.dart @@ -1,16 +1,12 @@ import 'package:chat/models/user_info_model.dart'; class AuthModel { - String tokenType; String accessToken; String userSig; String userID; UserInfoModel userInfo; - String get userToken => '$tokenType $accessToken'; - AuthModel({ - required this.tokenType, required this.accessToken, required this.userID, required this.userSig, @@ -18,9 +14,8 @@ class AuthModel { }); factory AuthModel.fromJson(Map json) => AuthModel( - tokenType: json['token_type'], accessToken: json['access_token'], - userID: json['user_id'], + userID: json['user_id'].toString(), userSig: json['user_sig'], userInfo: UserInfoModel.fromJson(json['user_info']), ); diff --git a/lib/models/user_info_model.dart b/lib/models/user_info_model.dart index dc7aa71..d416c3c 100644 --- a/lib/models/user_info_model.dart +++ b/lib/models/user_info_model.dart @@ -7,14 +7,14 @@ class UserInfoModel { required this.address, }); - int userId; + String userId; String username; - String nickname; - String avatar; + String? nickname; + String? avatar; String? address; factory UserInfoModel.fromJson(Map json) => UserInfoModel( - userId: json['user_id'], + userId: json['user_id'].toString(), username: json['username'], nickname: json['nickname'], avatar: json['avatar'], @@ -22,10 +22,18 @@ class UserInfoModel { ); factory UserInfoModel.empty() => UserInfoModel( - userId: 0, + userId: '', username: '', nickname: '', avatar: '', address: '', ); + + Map toJson() => { + "userId": userId, + "username": username, + "nickname": nickname, + "avatar": avatar, + "address": address, + }; } diff --git a/lib/providers/auth_provider.dart b/lib/providers/auth_provider.dart index 44e4f94..74ade00 100644 --- a/lib/providers/auth_provider.dart +++ b/lib/providers/auth_provider.dart @@ -14,7 +14,7 @@ class AuthProvider { return AuthModel.fromJson(result); } catch (e) { - UiTools.toast('区块链地址获取失败'); + UiTools.toast('区块链地址获取失败 ${e.toString()}'); return null; } } diff --git a/lib/services/auth_service.dart b/lib/services/auth_service.dart index e05bd17..10b5dc7 100644 --- a/lib/services/auth_service.dart +++ b/lib/services/auth_service.dart @@ -25,6 +25,7 @@ class AuthService extends GetxService { String get _userId => _box.read('userId') ?? ''; String get _userSig => _box.read('userSig') ?? ''; String get _userToken => _box.read('userToken') ?? ''; + Map get _userInfo => _box.read('userInfo') ?? {}; Rx userInfo = UserInfoModel.empty().obs; @@ -37,6 +38,7 @@ class AuthService extends GetxService { userSig = _userSig; userId = _userId; userToken = _userToken; + userInfo.value = UserInfoModel.fromJson(_userInfo); } } @@ -46,11 +48,13 @@ class AuthService extends GetxService { if (result != null) { _box.write('userId', result.userID); _box.write('userSig', result.userSig); - _box.write('userToken', result.userToken); + _box.write('userToken', result.accessToken); + _box.write('userInfo', result.userInfo.toJson()); userId = result.userID; userSig = result.userSig; - userToken = result.userToken; + userToken = result.accessToken; + userInfo.value = result.userInfo; isLogin.value = true; diff --git a/lib/utils/request/http_options.dart b/lib/utils/request/http_options.dart index 54fd532..94f52de 100644 --- a/lib/utils/request/http_options.dart +++ b/lib/utils/request/http_options.dart @@ -1,5 +1,5 @@ class HttpOptions { - static const String baseUrl = 'http://api.gl.shangkelian.cn/api/'; + static const String baseUrl = 'https://zh-chat.cnskl.com/api/'; static const int connectTimeout = 15000; static const int receiveTimeout = 15000; } diff --git a/lib/views/auth/create/index_page.dart b/lib/views/auth/create/index_page.dart index 32d06e9..5a6c87e 100644 --- a/lib/views/auth/create/index_page.dart +++ b/lib/views/auth/create/index_page.dart @@ -46,93 +46,95 @@ class _AuthCreatePageState extends State @override Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const Text('备份助记词'), - actions: [ - TextButton( - onPressed: () {}, - child: const Text('跳过备份'), - ), - ], - ), - body: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - TabBar( - controller: _tabController, - isScrollable: true, - indicatorColor: AppColors.primary, - indicatorWeight: 5, - indicatorSize: TabBarIndicatorSize.label, - tabs: const [ - Tab( - text: 'English', - ), - Tab( - text: '中文', - ), - ], - ), - const Padding( - padding: EdgeInsets.only(right: 8.0), - child: Text( - '请务必抄下助记词,确定之后将进行校验', - style: TextStyle( - fontSize: 12, + return SafeArea( + child: Scaffold( + appBar: AppBar( + title: const Text('备份助记词'), + actions: [ + TextButton( + onPressed: () {}, + child: const Text('跳过备份'), + ), + ], + ), + body: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + TabBar( + controller: _tabController, + isScrollable: true, + indicatorColor: AppColors.primary, + indicatorWeight: 5, + indicatorSize: TabBarIndicatorSize.label, + tabs: const [ + Tab( + text: 'English', + ), + Tab( + text: '中文', + ), + ], + ), + const Padding( + padding: EdgeInsets.only(right: 8.0), + child: Text( + '请务必抄下助记词,确定之后将进行校验', + style: TextStyle( + fontSize: 12, + ), ), ), - ), - ], - ), - Expanded( - child: TabBarView( - controller: _tabController, - children: [ - _moArea(_englishMnemonic), - _moArea(_chineseMnemonic), ], ), - ), - Container( - height: Get.height * 0.382, - padding: const EdgeInsets.all(16), - child: const Text( - '提示:请勿截图!如果有人获取您的助记词将直接获取您的资产,请抄写助记词并存放在安全的地方,我们会在下一屏幕进行校验,', + Expanded( + child: TabBarView( + controller: _tabController, + children: [ + _moArea(_englishMnemonic), + _moArea(_chineseMnemonic), + ], + ), ), - ), - Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - ElevatedButton( - onPressed: () { - _generateMnemonic(); - }, - child: const Text('更换助记词'), + Container( + height: Get.height * 0.382, + padding: const EdgeInsets.all(16), + child: const Text( + '提示:请勿截图!如果有人获取您的助记词将直接获取您的资产,请抄写助记词并存放在安全的地方,我们会在下一屏幕进行校验,', ), - ElevatedButton( - onPressed: () { - var language = _tabController.index; - Get.toNamed( - AuthRoutes.createVerify, - arguments: { - 'language': language == 0 ? 'english' : 'chinese', - 'mnemonic': - language == 0 ? _englishMnemonic : _chineseMnemonic - }, - ); - }, - child: const Text('开始备份'), - ), - ], - ), - const SizedBox( - height: 16, - ), - ], + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + ElevatedButton( + onPressed: () { + _generateMnemonic(); + }, + child: const Text('更换助记词'), + ), + ElevatedButton( + onPressed: () { + var language = _tabController.index; + Get.toNamed( + AuthRoutes.createVerify, + arguments: { + 'language': language == 0 ? 'english' : 'chinese', + 'mnemonic': + language == 0 ? _englishMnemonic : _chineseMnemonic + }, + ); + }, + child: const Text('开始备份'), + ), + ], + ), + const SizedBox( + height: 16, + ), + ], + ), ), ); } diff --git a/lib/views/auth/import/index_page.dart b/lib/views/auth/import/index_page.dart index a89cfcb..87d94c9 100644 --- a/lib/views/auth/import/index_page.dart +++ b/lib/views/auth/import/index_page.dart @@ -37,36 +37,41 @@ class _AuthImportPageState extends State { appBar: AppBar( title: const Text('导入账户'), ), - body: Column( - children: [ - TextField( - controller: _editingController, - maxLines: 4, - decoration: const InputDecoration( - hintText: '请输入您的助记词', - border: OutlineInputBorder( - borderSide: BorderSide( - color: AppColors.border, - width: 0.4, + body: Padding( + padding: const EdgeInsets.all(16.0), + child: Column( + children: [ + TextField( + controller: _editingController, + maxLines: 5, + decoration: const InputDecoration( + hintText: '请输入您的助记词,以空格分割单词或汉字', + border: OutlineInputBorder( + borderSide: BorderSide( + color: AppColors.border, + width: 0.4, + ), ), ), ), - ), - const Text('支持导入所有遵循BIP标准生成的助记词'), - ElevatedButton( - onPressed: () async { - String? address = - HDWallet.mnemonicToAddress(_editingController.text); - if (address != null) { - var result = await AuthService.to.login(address); - if (result) { - Get.offAllNamed(AppRoutes.app); + const SizedBox(height: 16), + const Text('支持导入所有遵循BIP标准生成的助记词'), + const SizedBox(height: 16), + ElevatedButton( + onPressed: () async { + String? address = + HDWallet.mnemonicToAddress(_editingController.text); + if (address != null) { + var result = await AuthService.to.login(address); + if (result) { + Get.offAllNamed(AppRoutes.app); + } } - } - }, - child: const Text('开始导入'), - ), - ], + }, + child: const Text('开始导入'), + ), + ], + ), ), ); } diff --git a/lib/views/auth/index/index_page.dart b/lib/views/auth/index/index_page.dart index 9e8514d..8c76401 100644 --- a/lib/views/auth/index/index_page.dart +++ b/lib/views/auth/index/index_page.dart @@ -18,17 +18,22 @@ class _AuthPageState extends State { ), body: Column( children: [ - ElevatedButton( - onPressed: () { - Get.toNamed(AuthRoutes.create); - }, - child: const Text('创建账户'), - ), - ElevatedButton( - onPressed: () { - Get.toNamed(AuthRoutes.import); - }, - child: const Text('导入账户'), + Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + ElevatedButton( + onPressed: () { + Get.toNamed(AuthRoutes.create); + }, + child: const Text('创建账户'), + ), + ElevatedButton( + onPressed: () { + Get.toNamed(AuthRoutes.import); + }, + child: const Text('导入账户'), + ), + ], ), ], ), diff --git a/lib/views/moments/index/widgets/quick_reply_bar.dart b/lib/views/moments/index/widgets/quick_reply_bar.dart index d49183e..031d17a 100644 --- a/lib/views/moments/index/widgets/quick_reply_bar.dart +++ b/lib/views/moments/index/widgets/quick_reply_bar.dart @@ -49,7 +49,7 @@ class _QuickReplyBarState extends State { border: QuickReplyBar._border, focusedBorder: QuickReplyBar._border, disabledBorder: QuickReplyBar._border, - hintText: widget.comment?.user?.nickname.isNotEmpty ?? false + hintText: widget.comment?.user?.nickname != null ? '回复:${widget.comment?.user?.nickname}' : '评论', filled: true, diff --git a/lib/views/user/index/user_page.dart b/lib/views/user/index/user_page.dart index ea76fb9..0ed503a 100644 --- a/lib/views/user/index/user_page.dart +++ b/lib/views/user/index/user_page.dart @@ -27,7 +27,7 @@ class _UserPageState extends State { ), Column( children: [ - Text(_.userInfo.value.nickname), + Text(_.userInfo.value.nickname ?? ''), Text('${_.userInfo.value.address}'), ], ),