17 changed files with 337 additions and 54 deletions
Split View
Diff Options
-
5android/app/build.gradle
-
17lib/config/app_config.dart
-
5lib/http/request.dart
-
18lib/main.dart
-
18lib/pages/index_page.dart
-
35lib/pages/test_page.dart
-
45lib/router/app_router.dart
-
5lib/router/application.dart
-
10lib/router/route_paths.dart
-
18lib/router/router.dart
-
8lib/router/router_handles.dart
-
50lib/utils/utils.dart
-
4macos/Flutter/GeneratedPluginRegistrant.swift
-
136pubspec.lock
-
5pubspec.yaml
-
9windows/flutter/generated_plugin_registrant.cc
-
3windows/flutter/generated_plugins.cmake
@ -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'); |
|||
} |
|||
} |
|||
} |
|||
@ -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<TestPage> createState() => _TestPageState(); |
|||
} |
|||
|
|||
class _TestPageState extends State<TestPage> { |
|||
@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返回'), |
|||
), |
|||
], |
|||
), |
|||
); |
|||
} |
|||
} |
|||
@ -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<NavigatorState> _rootKey = GlobalKey<NavigatorState>(); |
|||
|
|||
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); |
|||
}, |
|||
), |
|||
|
|||
|
|||
], |
|||
|
|||
); |
|||
} |
|||
@ -1,5 +0,0 @@ |
|||
import 'package:fluro/fluro.dart'; |
|||
|
|||
class Application { |
|||
static late final FluroRouter router; |
|||
} |
|||
@ -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'; |
|||
} |
|||
@ -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<String, List<String>> params) { |
|||
return; |
|||
} |
|||
); |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -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'; |
|||
|
|||
|
|||
|
|||
Write
Preview
Loading…
Cancel
Save