24
This commit is contained in:
44
lib/v12/app/navigation/router/app.dart
Normal file
44
lib/v12/app/navigation/router/app.dart
Normal file
@@ -0,0 +1,44 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../../pages/counter/counter_page.dart';
|
||||
import '../../../pages/user/user_page.dart';
|
||||
import '../../../pages/settings/settings_page.dart';
|
||||
import '../../../pages/empty/empty_panel.dart';
|
||||
import '../views/app_navigation.dart';
|
||||
import 'color.dart';
|
||||
import 'sort.dart';
|
||||
|
||||
|
||||
final RouteBase appRoute = ShellRoute(
|
||||
builder: (BuildContext context, GoRouterState state, Widget child) {
|
||||
return AppNavigation(navigator: child);
|
||||
},
|
||||
routes: <RouteBase>[
|
||||
colorRouters,
|
||||
GoRoute(
|
||||
path: 'counter',
|
||||
builder: (BuildContext context, GoRouterState state) {
|
||||
return const CounterPage();
|
||||
}),
|
||||
sortRouters,
|
||||
GoRoute(
|
||||
path: 'user',
|
||||
builder: (BuildContext context, GoRouterState state) {
|
||||
return const UserPage();
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: 'settings',
|
||||
builder: (BuildContext context, GoRouterState state) {
|
||||
return const SettingPage();
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: '404',
|
||||
builder: (BuildContext context, GoRouterState state) {
|
||||
String msg = '无法访问: ${state.extra}';
|
||||
return EmptyPanel(msg: msg);
|
||||
},
|
||||
)
|
||||
],
|
||||
);
|
||||
35
lib/v12/app/navigation/router/color.dart
Normal file
35
lib/v12/app/navigation/router/color.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../../pages/color/color_add_page.dart';
|
||||
import '../../../pages/color/color_detail_page.dart';
|
||||
import '../../../pages/color/color_page.dart';
|
||||
|
||||
|
||||
|
||||
final RouteBase colorRouters = GoRoute(
|
||||
path: 'color',
|
||||
builder: (BuildContext context, GoRouterState state) {
|
||||
return const ColorPage();
|
||||
},
|
||||
routes: <RouteBase>[
|
||||
GoRoute(
|
||||
path: 'detail',
|
||||
name: 'colorDetail',
|
||||
builder: (BuildContext context, GoRouterState state) {
|
||||
String? selectedColor = state.uri.queryParameters['color'];
|
||||
Color color = Colors.black;
|
||||
if (selectedColor != null) {
|
||||
color = Color(int.parse(selectedColor, radix: 16));
|
||||
}
|
||||
return ColorDetailPage(color: color);
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: 'add',
|
||||
builder: (BuildContext context, GoRouterState state) {
|
||||
return const ColorAddPage();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
27
lib/v12/app/navigation/router/root.dart
Normal file
27
lib/v12/app/navigation/router/root.dart
Normal file
@@ -0,0 +1,27 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../../pages/login/login.dart';
|
||||
import 'app.dart';
|
||||
|
||||
final RouteBase rootRoute = GoRoute(
|
||||
path: '/',
|
||||
redirect: _redirect,
|
||||
routes: [
|
||||
appRoute,
|
||||
GoRoute(
|
||||
path: 'login',
|
||||
builder: (BuildContext context, GoRouterState state) {
|
||||
return const LoginPage();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
FutureOr<String?> _redirect(BuildContext context, GoRouterState state) {
|
||||
if(state.fullPath=='/'){
|
||||
return '/color';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
44
lib/v12/app/navigation/router/sort.dart
Normal file
44
lib/v12/app/navigation/router/sort.dart
Normal file
@@ -0,0 +1,44 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../../pages/sort/provider/state.dart';
|
||||
|
||||
import '../../../pages/sort/views/player/sort_player.dart';
|
||||
import '../../../pages/sort/views/settings/sort_setting.dart';
|
||||
import '../../../pages/sort/views/sort_page/sort_page.dart';
|
||||
|
||||
final RouteBase sortRouters = ShellRoute(
|
||||
builder: (BuildContext context, GoRouterState state, Widget child) {
|
||||
return SortNavigation(navigator: child);
|
||||
},
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: 'sort',
|
||||
redirect: _redirectSort,
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: 'player/:name',
|
||||
builder: (BuildContext context, GoRouterState state) {
|
||||
print(state.pathParameters);// 获取路径参数
|
||||
return const SortPlayer();
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: 'settings',
|
||||
builder: (BuildContext context, GoRouterState state) {
|
||||
return const SortSettings();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
FutureOr<String?> _redirectSort(BuildContext context, GoRouterState state) {
|
||||
if (state.fullPath == '/sort') {
|
||||
String name = SortStateScope.read(context).config.name;
|
||||
return '/sort/player/$name';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user