diff --git a/lib/providers/public_provider.dart b/lib/providers/public_provider.dart index 801fe63..b82379b 100644 --- a/lib/providers/public_provider.dart +++ b/lib/providers/public_provider.dart @@ -1,16 +1,22 @@ import 'package:chat/utils/network/http.dart'; import 'package:chat/utils/ui_tools.dart'; +import 'package:package_info_plus/package_info_plus.dart'; class PublicProvider { /// 检测更新 - static Future checkUpgrade() async { + static Future checkUpgrade(PackageInfo? packageInfo) async { try { - return await Http.get( - 'version/check', - params: { - 'version': '', - }, - ); + if (packageInfo == null) { + return null; + } else { + return await Http.get( + 'version/check', + params: { + 'package_name': packageInfo.packageName, + 'version': packageInfo.version, + }, + ); + } } catch (e) { UiTools.toast(e.toString()); } diff --git a/lib/routes/app_routes.dart b/lib/routes/app_routes.dart index 7e25e1a..42654b5 100644 --- a/lib/routes/app_routes.dart +++ b/lib/routes/app_routes.dart @@ -1,6 +1,7 @@ import 'package:chat/views/home/index_page.dart'; import 'package:chat/views/public/app_page.dart'; -import 'package:chat/views/public/scan_page.dart'; +import 'package:chat/views/public/result_page.dart'; +import 'package:chat/views/public/scan/index_page.dart'; import 'package:chat/views/public/transit_page.dart'; import 'package:chat/views/search/index_page.dart'; import 'package:get/get.dart'; @@ -12,6 +13,7 @@ abstract class AppRoutes { static const String transit = '/transit'; static const String notfound = '/notfound'; static const String scan = '/scan'; + static const String scanResult = '/scan/result'; static const String home = '/home'; static const String search = '/search'; @@ -27,6 +29,12 @@ abstract class AppRoutes { GetPage( name: AppRoutes.scan, page: () => const ScanPage(), + children: [ + GetPage( + name: '/result', + page: () => const ScanResultPage(), + ), + ], ), GetPage( name: AppRoutes.home, diff --git a/lib/views/public/result_page.dart b/lib/views/public/result_page.dart new file mode 100644 index 0000000..039d977 --- /dev/null +++ b/lib/views/public/result_page.dart @@ -0,0 +1,48 @@ +import 'package:chat/configs/app_colors.dart'; +import 'package:chat/utils/ui_tools.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:get/get.dart'; + +class ScanResultPage extends StatelessWidget { + const ScanResultPage({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + String content = Get.arguments; + return Scaffold( + backgroundColor: AppColors.white, + appBar: AppBar( + title: const Text('扫码结果'), + actions: [ + TextButton( + onPressed: () { + Clipboard.setData( + ClipboardData( + text: content, + ), + ); + UiTools.toast('复制成功'); + }, + child: const Text('复制结果'), + ), + ], + ), + body: ListView( + padding: const EdgeInsets.symmetric( + horizontal: 16, + vertical: 8, + ), + children: [ + Text( + content, + style: const TextStyle( + height: 1.5, + fontSize: 16, + ), + ), + ], + ), + ); + } +} diff --git a/lib/views/public/scan_page.dart b/lib/views/public/scan/index_page.dart similarity index 96% rename from lib/views/public/scan_page.dart rename to lib/views/public/scan/index_page.dart index 5b74ffd..9fee2b4 100644 --- a/lib/views/public/scan_page.dart +++ b/lib/views/public/scan/index_page.dart @@ -1,4 +1,5 @@ import 'package:chat/configs/app_colors.dart'; +import 'package:chat/routes/app_routes.dart'; import 'package:chat/routes/user_routes.dart'; import 'package:chat/utils/ui_tools.dart'; import 'package:flutter/material.dart'; @@ -24,17 +25,16 @@ class _ScanPageState extends State { switch (split.first) { case 'TRANSFER': - // 处理扫码转账 - Get.back(result: split.last); break; case 'BEFRIEND': - // 加好友 break; case 'JOINGROUP': - // 加群 break; default: - UiTools.toast(str); + Get.offNamed( + AppRoutes.scanResult, + arguments: str, + ); } } diff --git a/lib/views/user/qr_code/index_page.dart b/lib/views/user/qr_code/index_page.dart index f46e75b..35a9df5 100644 --- a/lib/views/user/qr_code/index_page.dart +++ b/lib/views/user/qr_code/index_page.dart @@ -1,7 +1,7 @@ import 'package:chat/configs/app_colors.dart'; import 'package:chat/services/auth_service.dart'; import 'package:chat/views/home/widgets/pop_menu_item.dart'; -import 'package:chat/views/public/scan_page.dart'; +import 'package:chat/views/public/scan/index_page.dart'; import 'package:chat/widgets/custom_avatar.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; diff --git a/lib/views/user/setting/index_page.dart b/lib/views/user/setting/index_page.dart index a0eb7c4..751fbf9 100644 --- a/lib/views/user/setting/index_page.dart +++ b/lib/views/user/setting/index_page.dart @@ -1,11 +1,13 @@ import 'package:adaptive_dialog/adaptive_dialog.dart'; import 'package:chat/configs/app_colors.dart'; +import 'package:chat/providers/public_provider.dart'; import 'package:chat/routes/user_routes.dart'; import 'package:chat/services/auth_service.dart'; import 'package:chat/views/home/widgets/action_button.dart'; import 'package:chat/views/home/widgets/action_item.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import 'package:package_info_plus/package_info_plus.dart'; class UserSettingPage extends StatefulWidget { const UserSettingPage({Key? key}) : super(key: key); @@ -15,6 +17,18 @@ class UserSettingPage extends StatefulWidget { } class _UserSettingPageState extends State { + PackageInfo? packageInfo; + + @override + void initState() { + super.initState(); + PackageInfo.fromPlatform().then((value) { + setState(() { + packageInfo = value; + }); + }); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -63,10 +77,12 @@ class _UserSettingPageState extends State { const SizedBox(height: 8), ActionItem( '版本更新', - extend: '1.0.0', + extend: packageInfo?.version, isFirst: true, isLast: true, - onTap: () {}, + onTap: () async { + PublicProvider.checkUpgrade(packageInfo); + }, ), const SizedBox(height: 8), ActionButton( diff --git a/lib/views/user/share/index_page.dart b/lib/views/user/share/index_page.dart index 1f64c04..0008c04 100644 --- a/lib/views/user/share/index_page.dart +++ b/lib/views/user/share/index_page.dart @@ -1,3 +1,4 @@ +import 'package:chat/configs/app_colors.dart'; import 'package:chat/providers/user_provider.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; @@ -20,18 +21,28 @@ class _UserSharePageState extends State { body: FutureBuilder( future: UserProvider.downloadUrl(), builder: (context, AsyncSnapshot data) { - return Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - QrImage( - data: '${data.data}', - size: Get.width * 0.8, - ), - const Text('扫一扫上面的二维码,下载ZH-CHAT'), - ], - ), - ); + return data.data != null + ? Center( + child: Container( + decoration: BoxDecoration( + color: AppColors.white, + borderRadius: BorderRadius.circular(8), + ), + padding: const EdgeInsets.all(16), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + mainAxisSize: MainAxisSize.min, + children: [ + QrImage( + data: '${data.data}', + size: Get.width * 0.8, + ), + const Text('扫一扫上面的二维码,下载ZH-CHAT'), + ], + ), + ), + ) + : Container(); }, ), ); diff --git a/pubspec.lock b/pubspec.lock index 60fc5a2..f11919b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -28,7 +28,7 @@ packages: name: asn1lib url: "https://pub.flutter-io.cn" source: hosted - version: "1.2.2" + version: "1.3.0" async: dependency: transitive description: @@ -336,7 +336,7 @@ packages: name: flutter_plugin_record_plus url: "https://pub.flutter-io.cn" source: hosted - version: "0.0.11" + version: "0.0.15" flutter_spinkit: dependency: "direct main" description: @@ -556,7 +556,49 @@ packages: name: otp url: "https://pub.flutter-io.cn" source: hosted - version: "3.1.1" + version: "3.1.3" + package_info_plus: + dependency: "direct main" + description: + name: package_info_plus + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.4.2" + package_info_plus_linux: + dependency: transitive + description: + name: package_info_plus_linux + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.5" + package_info_plus_macos: + dependency: transitive + description: + name: package_info_plus_macos + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.3.0" + package_info_plus_platform_interface: + dependency: transitive + description: + name: package_info_plus_platform_interface + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.2" + package_info_plus_web: + dependency: "direct main" + description: + name: package_info_plus_web + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.6" + package_info_plus_windows: + dependency: transitive + description: + name: package_info_plus_windows + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.5" path: dependency: transitive description: @@ -745,7 +787,7 @@ packages: name: rxdart url: "https://pub.flutter-io.cn" source: hosted - version: "0.27.5" + version: "0.27.6" scan: dependency: "direct main" description: @@ -820,7 +862,7 @@ packages: name: stream_transform url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.1" + version: "2.1.0" string_scanner: dependency: transitive description: @@ -890,7 +932,7 @@ packages: name: uuid url: "https://pub.flutter-io.cn" source: hosted - version: "3.0.6" + version: "3.0.7" vector_math: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index e30c780..3f1ff4b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -51,6 +51,8 @@ dependencies: filesize: ^2.0.1 file_picker: ^4.6.1 otp: ^3.1.1 + package_info_plus: ^1.4.2 + package_info_plus_web: ^1.0.6 dev_dependencies: flutter_test: