v10
This commit is contained in:
@@ -4,7 +4,7 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
import 'v10/app.dart';
|
||||
import 'v11/app.dart';
|
||||
|
||||
void main() {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
@@ -147,7 +147,6 @@ class CellIRoute extends IRouteNode {
|
||||
if (pageBuilder != null) {
|
||||
return pageBuilder!(context, config, child);
|
||||
}
|
||||
print("======CellIRoute#createCellPage${config.pageKey}=================");
|
||||
return MaterialPage(
|
||||
child: child,
|
||||
key: config.pageKey,
|
||||
|
||||
@@ -15,7 +15,7 @@ class AppRouterDelegate extends RouterDelegate<IRouteConfig>
|
||||
/// 核心数据,路由配置数据列表
|
||||
final List<IRouteConfig> _configs = [];
|
||||
|
||||
String get path => current.uri.path;
|
||||
String get path => current.uri.toString();
|
||||
|
||||
IRouteConfig get current => _configs.last;
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:iroute/v9/app/navigation/router/views/navigator_scope.dart';
|
||||
|
||||
import 'iroute_config.dart';
|
||||
import 'utils/path_utils.dart';
|
||||
|
||||
typedef IRoutePageBuilder = Page? Function(
|
||||
BuildContext context,
|
||||
@@ -55,7 +56,7 @@ abstract class IRouteNode {
|
||||
if (node.children.isNotEmpty) {
|
||||
target = prefix + target;
|
||||
|
||||
List<IRouteNode> nodes = node.children.where((e) => e.path == target).toList();
|
||||
List<IRouteNode> nodes = node.children.where((e) => _match(e.path,target)).toList();
|
||||
bool match = nodes.isNotEmpty;
|
||||
if (match) {
|
||||
IRouteNode matched = nodes.first;
|
||||
@@ -69,6 +70,14 @@ abstract class IRouteNode {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool _match(String path ,String target){
|
||||
if(!path.contains(':')){
|
||||
return path == target;
|
||||
}
|
||||
return patternToRegExp(path,[]).hasMatch(target);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// 优先调用 [pageBuilder] 构建 Page
|
||||
@@ -147,7 +156,6 @@ class CellIRoute extends IRouteNode {
|
||||
if (pageBuilder != null) {
|
||||
return pageBuilder!(context, config, child);
|
||||
}
|
||||
print("======CellIRoute#createCellPage${config.pageKey}=================");
|
||||
return MaterialPage(
|
||||
child: child,
|
||||
key: config.pageKey,
|
||||
|
||||
@@ -10,6 +10,7 @@ class IRouteConfig {
|
||||
final Object? extra;
|
||||
final bool forResult;
|
||||
final Uri uri;
|
||||
final Map<String,String>? pathParams;
|
||||
final bool keepAlive;
|
||||
final RouteStyle routeStyle;
|
||||
final bool recordHistory;
|
||||
@@ -18,12 +19,13 @@ class IRouteConfig {
|
||||
this.extra,
|
||||
required this.uri,
|
||||
this.forResult = false,
|
||||
this.pathParams,
|
||||
this.keepAlive = false,
|
||||
this.routeStyle = RouteStyle.replace,
|
||||
this.recordHistory = false,
|
||||
});
|
||||
|
||||
String get path => uri.path;
|
||||
String get path => uri.toString();
|
||||
|
||||
IRouteConfig copyWith({
|
||||
Object? extra,
|
||||
|
||||
@@ -43,7 +43,7 @@ CellIRoute appRoute = CellIRoute(
|
||||
widget: SortSettings(),
|
||||
),
|
||||
const IRoute(
|
||||
path: '/app/sort/player',
|
||||
path: '/app/sort/player/:name',
|
||||
widget: SortPlayer(),
|
||||
),
|
||||
],
|
||||
@@ -80,7 +80,7 @@ Map<String, String> kRouteLabelMap = {
|
||||
'/app/color/detail': '颜色详情',
|
||||
'/app/counter': '计数器',
|
||||
'/app/sort': '排序算法',
|
||||
'/app/sort/player': '演示',
|
||||
'/app/sort/:name': '',
|
||||
'/app/sort/settings': '排序配置',
|
||||
'/app/user': '我的',
|
||||
'/app/settings': '系统设置',
|
||||
|
||||
37
lib/v11/app/navigation/router/utils/path_utils.dart
Normal file
37
lib/v11/app/navigation/router/utils/path_utils.dart
Normal file
@@ -0,0 +1,37 @@
|
||||
final RegExp _parameterRegExp = RegExp(r':(\w+)(\((?:\\.|[^\\()])+\))?');
|
||||
|
||||
RegExp patternToRegExp(String pattern, List<String> parameters) {
|
||||
final StringBuffer buffer = StringBuffer('^');
|
||||
int start = 0;
|
||||
for (final RegExpMatch match in _parameterRegExp.allMatches(pattern)) {
|
||||
if (match.start > start) {
|
||||
buffer.write(RegExp.escape(pattern.substring(start, match.start)));
|
||||
}
|
||||
final String name = match[1]!;
|
||||
final String? optionalPattern = match[2];
|
||||
final String regex = optionalPattern != null
|
||||
? _escapeGroup(optionalPattern, name)
|
||||
: '(?<$name>[^/]+)';
|
||||
buffer.write(regex);
|
||||
parameters.add(name);
|
||||
start = match.end;
|
||||
}
|
||||
|
||||
if (start < pattern.length) {
|
||||
buffer.write(RegExp.escape(pattern.substring(start)));
|
||||
}
|
||||
|
||||
if (!pattern.endsWith('/')) {
|
||||
buffer.write(r'(?=/|$)');
|
||||
}
|
||||
return RegExp(buffer.toString(), caseSensitive: false);
|
||||
}
|
||||
|
||||
String _escapeGroup(String group, [String? name]) {
|
||||
final String escapedGroup = group.replaceFirstMapped(
|
||||
RegExp(r'[:=!]'), (Match match) => '\\${match[0]}');
|
||||
if (name != null) {
|
||||
return '(?<$name>$escapedGroup)';
|
||||
}
|
||||
return escapedGroup;
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:iroute/components/components.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../../pages/sort/provider/state.dart';
|
||||
import '../router/app_router_delegate.dart';
|
||||
import '../router/iroute_config.dart';
|
||||
import '../router/routes.dart';
|
||||
@@ -37,7 +39,7 @@ class _AppNavigationRailState extends State<AppNavigationRail> {
|
||||
tail: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 6.0),
|
||||
child: Text(
|
||||
'V0.0.10',
|
||||
'V0.0.11',
|
||||
style: TextStyle(color: Colors.white, fontSize: 12),
|
||||
),
|
||||
),
|
||||
@@ -66,6 +68,12 @@ class _AppNavigationRailState extends State<AppNavigationRail> {
|
||||
router.changePath(path, keepAlive: true,recordHistory: true);
|
||||
return;
|
||||
}
|
||||
if(index ==2){
|
||||
SortState state = SortStateScope.read(context);
|
||||
String name = state.config.name;
|
||||
router.changePath('/app/sort/$name',recordHistory: true);
|
||||
return;
|
||||
}
|
||||
if (index == 4) {
|
||||
router.changePath(path, style: RouteStyle.push,recordHistory: true);
|
||||
return;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:iroute/components/components.dart';
|
||||
import '../../../../pages/sort/provider/state.dart';
|
||||
import '../../router/app_router_delegate.dart';
|
||||
import '../../router/routes.dart';
|
||||
import '../../router/utils/path_utils.dart';
|
||||
import '../../router/views/route_back_indicator.dart';
|
||||
import 'app_router_editor.dart';
|
||||
import 'history_view_icon.dart';
|
||||
@@ -83,6 +85,13 @@ class _RouterIndicatorState extends State<RouterIndicator> {
|
||||
|
||||
void _onRouterChange() {
|
||||
setState(() {});
|
||||
if(router.path.startsWith('/app/sort/')){
|
||||
SortState state = SortStateScope.of(context);
|
||||
String name = router.path.replaceAll('/app/sort/', '');
|
||||
if(name!='settings'){
|
||||
state.selectName(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<BreadcrumbItem> pathToBreadcrumbItems(String path) {
|
||||
@@ -97,7 +106,12 @@ class _RouterIndicatorState extends State<RouterIndicator> {
|
||||
|
||||
for (String segment in uri.pathSegments) {
|
||||
to += '/$segment';
|
||||
String label = kRouteLabelMap[to] ?? '未知路由';
|
||||
String label = '';
|
||||
if(to.startsWith('/app/sort/')){
|
||||
label = to.replaceAll('/app/sort/', '');
|
||||
}else{
|
||||
label = kRouteLabelMap[to] ?? '未知路由';
|
||||
}
|
||||
if(label.isNotEmpty){
|
||||
result.add(BreadcrumbItem(to: to, label: label, active: to == distPath));
|
||||
}
|
||||
|
||||
@@ -48,9 +48,10 @@ class _ColorPageState extends State<ColorPage> {
|
||||
}
|
||||
|
||||
void _selectColor(Color color){
|
||||
// String value = color.value.toRadixString(16);
|
||||
// router.path = '/color/detail?color=$value';
|
||||
router.changePath('/app/color/detail',extra: color);
|
||||
String value = color.value.toRadixString(16);
|
||||
String path = '/app/color/detail?color=$value';
|
||||
// router.changePath('/app/color/detail',extra: color);
|
||||
router.changePath(path,recordHistory: true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -98,4 +98,7 @@ class SortStateScope extends InheritedNotifier<SortState> {
|
||||
|
||||
static SortState of(BuildContext context) =>
|
||||
context.dependOnInheritedWidgetOfExactType<SortStateScope>()!.notifier!;
|
||||
|
||||
static SortState read(BuildContext context) =>
|
||||
context.getInheritedWidgetOfExactType<SortStateScope>()!.notifier!;
|
||||
}
|
||||
@@ -81,7 +81,7 @@ class SortRailPanel extends StatelessWidget {
|
||||
options: sortNameMap.values.toList(),
|
||||
onSelected: (name) {
|
||||
state.selectName(name);
|
||||
router.changePath('/app/sort/player');
|
||||
router.changePath('/app/sort/${name}',recordHistory: true);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
@@ -148,7 +148,6 @@ class CellIRoute extends IRouteNode {
|
||||
if (pageBuilder != null) {
|
||||
return pageBuilder!(context, config, child);
|
||||
}
|
||||
print("======CellIRoute#createCellPage${config.pageKey}=================");
|
||||
return MaterialPage(
|
||||
child: child,
|
||||
key: config.pageKey,
|
||||
|
||||
Reference in New Issue
Block a user