From ec22583ebb3a21f3b0df1ef3d5ef27170d8b98b1 Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 1 Nov 2022 16:51:56 +0800 Subject: [PATCH] update --- lib/models/user_info_model.dart | 17 +++--- lib/providers/user_provider.dart | 4 ++ .../contact/firend/request/index_page.dart | 2 +- .../user/index/widgets/user_top_bar.dart | 5 +- lib/views/user/serve/google/index_page.dart | 42 ++++++++++++++- lib/views/user/serve/index_page.dart | 16 +++--- .../user/setting/privacy/index_page.dart | 2 +- lib/views/user/setting/safe/index_page.dart | 54 ++++++++++--------- pubspec.lock | 21 ++++++++ pubspec.yaml | 1 + 10 files changed, 119 insertions(+), 45 deletions(-) diff --git a/lib/models/user_info_model.dart b/lib/models/user_info_model.dart index dc66e34..a75f3e3 100644 --- a/lib/models/user_info_model.dart +++ b/lib/models/user_info_model.dart @@ -2,43 +2,48 @@ class UserInfoModel { UserInfoModel({ required this.userId, required this.username, + required this.mobile, + required this.email, required this.privacy, required this.nickname, required this.avatar, - required this.address, }); String userId; String username; - bool privacy; + String? mobile; + String? email; + bool? privacy; String? nickname; String? avatar; - String? address; factory UserInfoModel.fromJson(Map json) => UserInfoModel( userId: json['user_id'].toString(), username: json['username'], + mobile: json['mobile'], + email: json['email'], privacy: json['privacy'], nickname: json['nickname'], avatar: json['avatar'], - address: json['address'], ); factory UserInfoModel.empty() => UserInfoModel( userId: '', username: '', + mobile: '', + email: '', privacy: true, nickname: '', avatar: '', - address: '', ); Map toJson() => { "userId": userId, "username": username, + "mobile": mobile, + "email": email, "privacy": privacy, "nickname": nickname, "avatar": avatar, - "address": address, }; } diff --git a/lib/providers/user_provider.dart b/lib/providers/user_provider.dart index 024cbf2..d2e0378 100644 --- a/lib/providers/user_provider.dart +++ b/lib/providers/user_provider.dart @@ -72,4 +72,8 @@ class UserProvider { } return null; } + + static Future updateMobile(String mobile) async {} + + static Future updateEmail(String email) async {} } diff --git a/lib/views/contact/firend/request/index_page.dart b/lib/views/contact/firend/request/index_page.dart index 869fc0f..0e9c92d 100644 --- a/lib/views/contact/firend/request/index_page.dart +++ b/lib/views/contact/firend/request/index_page.dart @@ -277,7 +277,7 @@ class _Search extends StatelessWidget implements PreferredSizeWidget { Text( '我的地址: ' + Convert.hideCenterStr( - AuthService.to.userInfo.value.address!, + AuthService.to.userInfo.value.username, start: 4, end: 4, ), diff --git a/lib/views/user/index/widgets/user_top_bar.dart b/lib/views/user/index/widgets/user_top_bar.dart index b87d739..9c10b38 100644 --- a/lib/views/user/index/widgets/user_top_bar.dart +++ b/lib/views/user/index/widgets/user_top_bar.dart @@ -62,8 +62,7 @@ class UserTopBar extends StatelessWidget { Row( children: [ Text( - Convert.hideCenterStr( - _.userInfo.value.address ?? ''), + Convert.hideCenterStr(_.userInfo.value.username), style: const TextStyle( color: AppColors.unactive, ), @@ -73,7 +72,7 @@ class UserTopBar extends StatelessWidget { onTap: () { Clipboard.setData( ClipboardData( - text: _.userInfo.value.address, + text: _.userInfo.value.username, ), ); UiTools.toast('地址复制成功'); diff --git a/lib/views/user/serve/google/index_page.dart b/lib/views/user/serve/google/index_page.dart index fe6600b..f401e35 100644 --- a/lib/views/user/serve/google/index_page.dart +++ b/lib/views/user/serve/google/index_page.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:otp/otp.dart'; class UserServeGooglePage extends StatefulWidget { const UserServeGooglePage({Key? key}) : super(key: key); @@ -8,13 +9,52 @@ class UserServeGooglePage extends StatefulWidget { } class _UserServeGooglePageState extends State { + String code = '000000'; + String secret = 'T4UM3VPYXPALF7M5'; + int remaining = 0; + + @override + void initState() { + super.initState(); + getCode(); + } + + void getCode() { + setState(() { + remaining = OTP.remainingSeconds(); + + code = OTP.generateTOTPCodeString( + secret, + DateTime.now().millisecondsSinceEpoch, + algorithm: Algorithm.SHA1, + isGoogle: true, + ); + }); + } + @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('谷歌验证器'), ), - body: Container(), + body: Column( + children: [ + Text( + code, + style: const TextStyle( + fontSize: 32, + ), + ), + Text(remaining.toString()), + ElevatedButton( + onPressed: () { + getCode(); + }, + child: const Text('刷新密码'), + ), + ], + ), ); } } diff --git a/lib/views/user/serve/index_page.dart b/lib/views/user/serve/index_page.dart index 599cb06..fe57efd 100644 --- a/lib/views/user/serve/index_page.dart +++ b/lib/views/user/serve/index_page.dart @@ -1,5 +1,4 @@ import 'package:chat/routes/app_routes.dart'; -import 'package:chat/routes/user_routes.dart'; import 'package:chat/views/home/widgets/action_item.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; @@ -20,15 +19,16 @@ class _UserServePageState extends State { ), body: Column( children: [ - ActionItem( - '谷歌验证器', - isFirst: true, - onTap: () { - Get.toNamed(UserRoutes.serveGoogle); - }, - ), + // ActionItem( + // '谷歌验证器', + // isFirst: true, + // onTap: () { + // Get.toNamed(UserRoutes.serveGoogle); + // }, + // ), ActionItem( '扫一扫', + isFirst: true, isLast: true, onTap: () { Get.toNamed(AppRoutes.scan); diff --git a/lib/views/user/setting/privacy/index_page.dart b/lib/views/user/setting/privacy/index_page.dart index 010fbee..e4aa8bc 100644 --- a/lib/views/user/setting/privacy/index_page.dart +++ b/lib/views/user/setting/privacy/index_page.dart @@ -24,7 +24,7 @@ class UserSettingPrivacyPage extends StatelessWidget { return LinkActionItem( title: '允许通过搜索添加我为好友', trailing: Switch( - value: _.userInfo.value.privacy, + value: _.userInfo.value.privacy ?? true, materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, onChanged: (e) { _.togglePrivacy(); diff --git a/lib/views/user/setting/safe/index_page.dart b/lib/views/user/setting/safe/index_page.dart index e4ed494..d7829e5 100644 --- a/lib/views/user/setting/safe/index_page.dart +++ b/lib/views/user/setting/safe/index_page.dart @@ -21,31 +21,35 @@ class _UserSettingSafePageState extends State { appBar: AppBar( title: const Text('安全设置'), ), - body: Column( - children: [ - ActionItem( - '导出助记词', - isFirst: true, - isLast: true, - onTap: _showMnemonic, - ), - const SizedBox(height: 8), - ActionItem( - '绑定手机', - isFirst: true, - onTap: () { - Get.toNamed(UserRoutes.settingSafeMobile); - }, - ), - ActionItem( - '绑定邮箱', - isLast: true, - onTap: () { - Get.toNamed(UserRoutes.settingSafeEmail); - }, - ), - ], - ), + body: GetX(builder: (_) { + return Column( + children: [ + ActionItem( + '导出助记词', + isFirst: true, + isLast: true, + onTap: _showMnemonic, + ), + const SizedBox(height: 8), + ActionItem( + '绑定手机', + extend: _.userInfo.value.mobile ?? '未绑定', + isFirst: true, + onTap: () { + Get.toNamed(UserRoutes.settingSafeMobile); + }, + ), + ActionItem( + '绑定邮箱', + extend: _.userInfo.value.email ?? '未绑定', + isLast: true, + onTap: () { + Get.toNamed(UserRoutes.settingSafeEmail); + }, + ), + ], + ); + }), ); } diff --git a/pubspec.lock b/pubspec.lock index dd8f782..0fa1648 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -43,6 +43,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.0.0" + base32: + dependency: transitive + description: + name: base32 + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.1.3" bip32: dependency: "direct main" description: @@ -487,6 +494,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.0.1" + logging: + dependency: transitive + description: + name: logging + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.1.0" lpinyin: dependency: "direct main" description: @@ -543,6 +557,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "3.2.1" + otp: + dependency: "direct main" + description: + name: otp + url: "https://pub.flutter-io.cn" + source: hosted + version: "3.1.1" package_info_plus: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 18d6595..adbccb2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -52,6 +52,7 @@ dependencies: wechat_camera_picker: ^3.5.0+1 filesize: ^2.0.1 file_picker: ^4.6.1 + otp: ^3.1.1 dev_dependencies: flutter_test: