From 648700209f018964818bb5a8677f3f532177d2c2 Mon Sep 17 00:00:00 2001 From: YakumoChen Date: Thu, 30 Oct 2025 20:25:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=83=A8=E5=88=86=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E5=BA=93=EF=BC=8C=E8=A7=A3=E5=86=B3=E5=BA=93=E4=B9=8B?= =?UTF-8?q?=E9=97=B4=E7=9A=84=E5=86=B2=E7=AA=81=EF=BC=8C=E6=9B=B4=E6=8D=A2?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E6=8F=92=E4=BB=B6=E4=B8=BA=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=9A=84gorouter=E5=B9=B6=E5=A2=9E=E5=8A=A0=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B=EF=BC=8C=E5=A2=9E=E5=8A=A0=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=AF=B9=E5=BA=94=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android/app/build.gradle | 5 + lib/config/app_config.dart | 17 +++ lib/http/request.dart | 5 +- lib/main.dart | 18 +-- lib/pages/index_page.dart | 18 ++- lib/pages/test_page.dart | 35 +++++ lib/router/app_router.dart | 45 ++++++ lib/router/application.dart | 5 - lib/router/route_paths.dart | 10 ++ lib/router/router.dart | 18 --- lib/router/router_handles.dart | 8 -- lib/utils/utils.dart | 50 +++++++ macos/Flutter/GeneratedPluginRegistrant.swift | 4 + pubspec.lock | 136 ++++++++++++++++-- pubspec.yaml | 5 +- .../flutter/generated_plugin_registrant.cc | 9 ++ windows/flutter/generated_plugins.cmake | 3 + 17 files changed, 337 insertions(+), 54 deletions(-) create mode 100644 lib/config/app_config.dart create mode 100644 lib/pages/test_page.dart create mode 100644 lib/router/app_router.dart delete mode 100644 lib/router/application.dart create mode 100644 lib/router/route_paths.dart delete mode 100644 lib/router/router.dart delete mode 100644 lib/router/router_handles.dart diff --git a/android/app/build.gradle b/android/app/build.gradle index 90c2024..d6e389d 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -76,6 +76,11 @@ android { } } + + packagingOptions { + pickFirst 'lib/**/libaosl.so' + } + } flutter { diff --git a/lib/config/app_config.dart b/lib/config/app_config.dart new file mode 100644 index 0000000..ddb4784 --- /dev/null +++ b/lib/config/app_config.dart @@ -0,0 +1,17 @@ +class AppConfig { + final String baseUrl; + + const AppConfig._(this.baseUrl); + + // 根据不同环境返回不同配置 + static AppConfig fromEnv(String env) { + switch (env) { + case 'prod': + return const AppConfig._('https://api.example.com'); + case 'test': + return const AppConfig._('https://test-api.example.com'); + default: + return const AppConfig._('https://dev-api.example.com'); + } + } +} diff --git a/lib/http/request.dart b/lib/http/request.dart index 92fafb7..ed0f351 100644 --- a/lib/http/request.dart +++ b/lib/http/request.dart @@ -1,3 +1,4 @@ +import 'package:dating_touchme_app/config/app_config.dart'; import 'package:dio/dio.dart'; import 'package:dating_touchme_app/utils/storage.dart'; import 'dart:convert'; @@ -27,9 +28,11 @@ class Request { /// 初始化 Request._internal() { + const env = String.fromEnvironment('ENV', defaultValue: 'dev'); + final config = AppConfig.fromEnv(env); // 初始化基本选项 BaseOptions options = BaseOptions( - baseUrl: "http://www.example.com", + baseUrl: config.baseUrl, connectTimeout: const Duration(seconds: 20), receiveTimeout: const Duration(seconds: 20)); _instance = this; diff --git a/lib/main.dart b/lib/main.dart index ff4f069..dc1cd41 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,21 +1,21 @@ import 'package:dating_touchme_app/pages/home_page.dart'; import 'package:dating_touchme_app/pages/index_page.dart'; import 'package:dating_touchme_app/provide/user_info.dart'; +import 'package:dating_touchme_app/router/app_router.dart'; import 'package:dating_touchme_app/utils/global_modal.dart'; -import 'package:fluro/fluro.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; -import 'router/router.dart'; -import 'router/application.dart'; import 'package:provider/provider.dart'; void main() { - runApp(const MyApp()); + final appRouter = AppRouter(); + runApp(MyApp(routerConfig: appRouter.router,)); } class MyApp extends StatefulWidget { - const MyApp({super.key}); + final RouterConfig routerConfig; + const MyApp({super.key, required this.routerConfig}); @override State createState() => _MyAppState(); @@ -26,9 +26,6 @@ class _MyAppState extends State { @override void initState(){ super.initState(); - final router = FluroRouter(); - Routes.configureRoutes(router); - Application.router = router; registerGlobalModals(); } @@ -44,13 +41,12 @@ class _MyAppState extends State { child: ScreenUtilInit( designSize: const Size(375, 667), builder: (context, child){ - return MaterialApp( + return MaterialApp.router( theme: ThemeData( scaffoldBackgroundColor: Colors.white, ), builder: (context, child) => GlobalModalHost(child: child ?? const SizedBox()), - home: const HomePage(), - onGenerateRoute: Application.router.generator, + routerConfig: widget.routerConfig, ); }, ), diff --git a/lib/pages/index_page.dart b/lib/pages/index_page.dart index d463d59..1a157e9 100644 --- a/lib/pages/index_page.dart +++ b/lib/pages/index_page.dart @@ -1,12 +1,14 @@ import 'package:dating_touchme_app/components/page_appbar.dart'; +import 'package:dating_touchme_app/config/app_config.dart'; import 'package:dating_touchme_app/http/api.dart'; import 'package:dating_touchme_app/model/user_data.dart'; import 'package:dating_touchme_app/provide/user_info.dart'; -import 'package:dating_touchme_app/router/application.dart'; +import 'package:dating_touchme_app/router/route_paths.dart'; import 'package:dating_touchme_app/utils/global_modal.dart'; import 'package:dating_touchme_app/utils/storage.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:go_router/go_router.dart'; import 'package:provider/provider.dart'; class IndexPage extends StatefulWidget { @@ -27,8 +29,13 @@ class _IndexPageState extends State { @override void initState() { - // TODO: implement initState super.initState(); + + + const env = String.fromEnvironment('ENV', defaultValue: 'dev'); + final config = AppConfig.fromEnv(env); + + print(config.baseUrl); } @@ -90,6 +97,13 @@ class _IndexPageState extends State { }, child: const Text('模拟直播连麦邀请'), ), + const SizedBox(height: 12), + ElevatedButton( + onPressed: () async { + context.pushNamed(RouteNames.test, queryParameters: {'a': '10', 'b': '20'}); + }, + child: const Text('测试go router跳转'), + ), ], ); } diff --git a/lib/pages/test_page.dart b/lib/pages/test_page.dart new file mode 100644 index 0000000..f959fe8 --- /dev/null +++ b/lib/pages/test_page.dart @@ -0,0 +1,35 @@ +import 'package:dating_touchme_app/components/page_appbar.dart'; +import 'package:flutter/material.dart'; +import 'package:go_router/go_router.dart'; + +class TestPage extends StatefulWidget { + + final int a; + final int b; + + const TestPage({super.key, required this.a, required this.b}); + + @override + State createState() => _TestPageState(); +} + +class _TestPageState extends State { + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: PageAppbar(title: "路由测试",), + body: Column( + children: [ + Text("a = ${widget.a}"), + Text("b = ${widget.b}"), + ElevatedButton( + onPressed: () async { + context.pop(); + }, + child: const Text('测试go router返回'), + ), + ], + ), + ); + } +} diff --git a/lib/router/app_router.dart b/lib/router/app_router.dart new file mode 100644 index 0000000..934347b --- /dev/null +++ b/lib/router/app_router.dart @@ -0,0 +1,45 @@ +import 'package:dating_touchme_app/pages/home_page.dart'; +import 'package:dating_touchme_app/pages/test_page.dart'; +import 'package:dating_touchme_app/router/route_paths.dart'; +import 'package:flutter/material.dart'; +import 'package:go_router/go_router.dart'; + + +class AppRouter { + AppRouter(); + + // 根 Navigator(需要时可区分 root / shell 子导航) + final GlobalKey _rootKey = GlobalKey(); + + late final GoRouter router = GoRouter( + navigatorKey: _rootKey, + initialLocation: RoutePaths.home, + debugLogDiagnostics: true, // 开发期建议开启 + // 统一错误页 + errorBuilder: (context, state) => Scaffold( + body: Center( + child: Text('Oops: ${state.error?.toString() ?? 'Page not found'}'), + ), + ), + routes: [ + // 启动/闪屏(或可直接跳 home / login) + GoRoute( + name: RouteNames.home, + path: RoutePaths.home, + builder: (context, state) => const HomePage(), + ), + GoRoute( + name: RouteNames.test, + path: RoutePaths.test, + builder: (context, state) { + final a = int.parse(state.uri.queryParameters['a'] ?? '0'); + final b = int.parse(state.uri.queryParameters['b'] ?? '0'); + return TestPage(a: a, b: b); + }, + ), + + + ], + + ); +} diff --git a/lib/router/application.dart b/lib/router/application.dart deleted file mode 100644 index 66668ac..0000000 --- a/lib/router/application.dart +++ /dev/null @@ -1,5 +0,0 @@ -import 'package:fluro/fluro.dart'; - -class Application { - static late final FluroRouter router; -} \ No newline at end of file diff --git a/lib/router/route_paths.dart b/lib/router/route_paths.dart new file mode 100644 index 0000000..993e3fe --- /dev/null +++ b/lib/router/route_paths.dart @@ -0,0 +1,10 @@ +// lib/router/route_paths.dart +class RouteNames { + static const home = 'home'; + static const test = 'test'; +} + +class RoutePaths { + static const home = '/home'; + static const test = '/test'; +} diff --git a/lib/router/router.dart b/lib/router/router.dart deleted file mode 100644 index 395dd94..0000000 --- a/lib/router/router.dart +++ /dev/null @@ -1,18 +0,0 @@ -import 'package:fluro/fluro.dart'; -import 'package:dating_touchme_app/router/router_handles.dart'; -import 'package:flutter/cupertino.dart'; - - -class Routes{ - - - static void configureRoutes(FluroRouter router) { - router.notFoundHandler = Handler( - handlerFunc: (BuildContext? context, Map> params) { - return; - } - ); - } - - -} \ No newline at end of file diff --git a/lib/router/router_handles.dart b/lib/router/router_handles.dart deleted file mode 100644 index f6ba679..0000000 --- a/lib/router/router_handles.dart +++ /dev/null @@ -1,8 +0,0 @@ -import 'dart:convert'; - -import 'package:dating_touchme_app/pages/live_page.dart'; -import 'package:fluro/fluro.dart'; -import 'package:flutter/material.dart'; - - - diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index cad75e6..cf6189a 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -1,7 +1,10 @@ //各种封装的小函数 +import 'dart:async'; + import 'package:bruno/bruno.dart'; import 'package:flutter/material.dart'; +import 'package:permission_handler/permission_handler.dart'; void toast(String msg, BuildContext context){ BrnToast.show(msg, context); @@ -16,4 +19,51 @@ String formattedTime(int timestamp){ // 手动格式化日期和时间 String formattedDateTime = '${dateTime.year}-${dateTime.month.toString().padLeft(2, '0')}-${dateTime.day.toString().padLeft(2, '0')} ${dateTime.hour.toString().padLeft(2, '0')}:${dateTime.minute.toString().padLeft(2, '0')}:${dateTime.second.toString().padLeft(2, '0')}'; return formattedDateTime; +} + + + +Future handlePermission(BuildContext context, String content) async { + PermissionStatus status; + status = await Permission.location.status; + + final Completer completer = Completer(); + + if (status.isDenied) { + // 如果没有权限,显示权限提示弹窗 + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: Text("提示"), + content: Text(content), + actions: [ + TextButton( + child: Text("确定"), + onPressed: () async { + Map statuses; + statuses = await [ + Permission.location, + ].request(); + + Navigator.of(context).pop(); + completer.complete(true); + }, + ), + TextButton( + child: Text("取消"), + onPressed: () { + Navigator.of(context).pop(); + completer.complete(false); + }, + ), + ], + ); + }, + ); + } else { + completer.complete(true); + } + + return completer.future; } \ No newline at end of file diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index ab1fdba..6a65a78 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,10 +5,14 @@ import FlutterMacOS import Foundation +import agora_rtc_engine import file_selector_macos +import iris_method_channel import shared_preferences_foundation func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + AgoraRtcNgPlugin.register(with: registry.registrar(forPlugin: "AgoraRtcNgPlugin")) FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin")) + IrisMethodChannelPlugin.register(with: registry.registrar(forPlugin: "IrisMethodChannelPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) } diff --git a/pubspec.lock b/pubspec.lock index a99d672..cc3fd48 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,6 +1,14 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + agora_rtc_engine: + dependency: "direct main" + description: + name: agora_rtc_engine + sha256: "6559294d18ce4445420e19dbdba10fb58cac955cd8f22dbceae26716e194d70e" + url: "https://pub.flutter-io.cn" + source: hosted + version: "6.5.3" async: dependency: transitive description: @@ -153,14 +161,6 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "0.9.3+4" - fluro: - dependency: "direct main" - description: - name: fluro - sha256: "24d07d0b285b213ec2045b83e85d076185fa5c23651e44dae0ac6755784b97d0" - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.0.5" flutter: dependency: "direct main" description: flutter @@ -224,6 +224,14 @@ packages: description: flutter source: sdk version: "0.0.0" + go_router: + dependency: "direct main" + description: + name: go_router + sha256: "0b1e06223bee260dee31a171fb1153e306907563a0b0225e8c1733211911429a" + url: "https://pub.flutter-io.cn" + source: hosted + version: "15.1.2" http: dependency: transitive description: @@ -240,6 +248,38 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "4.0.2" + im_flutter_sdk: + dependency: "direct main" + description: + name: im_flutter_sdk + sha256: "952bd7a4846d9645adf6bf67c781573aba2825e12bbedfa7bb9f8b234bb1410b" + url: "https://pub.flutter-io.cn" + source: hosted + version: "4.15.1" + im_flutter_sdk_android: + dependency: transitive + description: + name: im_flutter_sdk_android + sha256: d809f8091b24bb70f55c8a1a040f7e0a27aef4756ac71549ce62e460f2151de6 + url: "https://pub.flutter-io.cn" + source: hosted + version: "4.15.1" + im_flutter_sdk_interface: + dependency: transitive + description: + name: im_flutter_sdk_interface + sha256: "82aef6f78bc7e4afc26768631262535b641cc885220981cc9deb871abf14efa8" + url: "https://pub.flutter-io.cn" + source: hosted + version: "4.15.1" + im_flutter_sdk_ios: + dependency: transitive + description: + name: im_flutter_sdk_ios + sha256: "5455ecd4e5877dd289051ca280ffb435d8f7f477a46f32bbb1bfc903dc03952a" + url: "https://pub.flutter-io.cn" + source: hosted + version: "4.15.1" image_picker: dependency: "direct overridden" description: @@ -312,6 +352,30 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "0.18.1" + iris_method_channel: + dependency: transitive + description: + name: iris_method_channel + sha256: bfb5cfc6c6eae42da8cd1b35977a72d8b8881848a5dfc3d672e4760a907d11a0 + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.2.4" + js: + dependency: transitive + description: + name: js + sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.7.1" + json_annotation: + dependency: transitive + description: + name: json_annotation + sha256: "1ce844379ca14835a50d2f019a3099f419082cfdd231cd86a142af94dd5c6bb1" + url: "https://pub.flutter-io.cn" + source: hosted + version: "4.9.0" leak_tracker: dependency: transitive description: @@ -344,6 +408,14 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "3.0.0" + logging: + dependency: transitive + description: + name: logging + sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61 + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.3.0" lpinyin: dependency: transitive description: @@ -440,6 +512,54 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.3.0" + permission_handler: + dependency: "direct main" + description: + name: permission_handler + sha256: "18bf33f7fefbd812f37e72091a15575e72d5318854877e0e4035a24ac1113ecb" + url: "https://pub.flutter-io.cn" + source: hosted + version: "11.3.1" + permission_handler_android: + dependency: transitive + description: + name: permission_handler_android + sha256: "71bbecfee799e65aff7c744761a57e817e73b738fedf62ab7afd5593da21f9f1" + url: "https://pub.flutter-io.cn" + source: hosted + version: "12.0.13" + permission_handler_apple: + dependency: transitive + description: + name: permission_handler_apple + sha256: f000131e755c54cf4d84a5d8bd6e4149e262cc31c5a8b1d698de1ac85fa41023 + url: "https://pub.flutter-io.cn" + source: hosted + version: "9.4.7" + permission_handler_html: + dependency: transitive + description: + name: permission_handler_html + sha256: "38f000e83355abb3392140f6bc3030660cfaef189e1f87824facb76300b4ff24" + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.1.3+5" + permission_handler_platform_interface: + dependency: transitive + description: + name: permission_handler_platform_interface + sha256: e9c8eadee926c4532d0305dff94b85bf961f16759c3af791486613152af4b4f9 + url: "https://pub.flutter-io.cn" + source: hosted + version: "4.2.3" + permission_handler_windows: + dependency: transitive + description: + name: permission_handler_windows + sha256: "1a790728016f79a41216d88672dbc5df30e686e811ad4e698bfc51f76ad91f1e" + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.2.1" petitparser: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 0ced9d3..06f57fe 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -37,11 +37,14 @@ dependencies: cupertino_icons: ^1.0.6 dio: ^5.4.2+1 flutter_screenutil: ^5.9.0 - fluro: ^2.0.5 provider: ^6.1.2 shared_preferences: ^2.2.3 tdesign_flutter: ^0.2.5 bruno: ^3.4.3 + agora_rtc_engine: ^6.5.3 + im_flutter_sdk: ^4.15.1 + go_router: ^15.1.2 + permission_handler: ^11.3.1 dependency_overrides: tdesign_flutter_adaptation: 3.16.0 diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 77ab7a0..16d71f5 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -6,9 +6,18 @@ #include "generated_plugin_registrant.h" +#include #include +#include +#include void RegisterPlugins(flutter::PluginRegistry* registry) { + AgoraRtcEnginePluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("AgoraRtcEnginePlugin")); FileSelectorWindowsRegisterWithRegistrar( registry->GetRegistrarForPlugin("FileSelectorWindows")); + IrisMethodChannelPluginCApiRegisterWithRegistrar( + registry->GetRegistrarForPlugin("IrisMethodChannelPluginCApi")); + PermissionHandlerWindowsPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index a423a02..970ef46 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -3,7 +3,10 @@ # list(APPEND FLUTTER_PLUGIN_LIST + agora_rtc_engine file_selector_windows + iris_method_channel + permission_handler_windows ) list(APPEND FLUTTER_FFI_PLUGIN_LIST