This commit is contained in:
toly
2023-11-08 09:35:29 +08:00
parent 88cd6fb3b4
commit 8fb4bf57d6
78 changed files with 4344 additions and 544 deletions

View File

@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'iroute_config.dart';
typedef IRoutePageBuilder = Page? Function(
@@ -24,7 +23,9 @@ abstract class IRouteNode {
Page? createPage(BuildContext context, IRouteConfig config);
List<IRouteNode> find(String input,) {
List<IRouteNode> find(
String input,
) {
return findNodes(this, Uri.parse(input), 0, '/', []);
}
@@ -41,15 +42,16 @@ abstract class IRouteNode {
}
String target = parts[deep];
if (node.children.isNotEmpty) {
target = prefix + target;
List<IRouteNode> nodes = node.children.where((e) => e.path == target).toList();
target = prefix + target;
List<IRouteNode> nodes =
node.children.where((e) => e.path == target).toList();
bool match = nodes.isNotEmpty;
if (match) {
IRouteNode matched = nodes.first;
result.add(matched);
String nextPrefix = '${matched.path}/';
findNodes(matched, uri, ++deep, nextPrefix, result);
}else{
} else {
result.add(NotFindNode(path: target));
return result;
}
@@ -92,8 +94,8 @@ class IRoute extends IRouteNode {
}
/// 未知路由
class NotFindNode extends IRouteNode{
NotFindNode({required super.path, super.children= const[]});
class NotFindNode extends IRouteNode {
NotFindNode({required super.path, super.children = const []});
@override
Page? createPage(BuildContext context, IRouteConfig config) {
@@ -101,15 +103,14 @@ class NotFindNode extends IRouteNode{
}
}
class CellIRouter extends IRoute {
final CellBuilder cellBuilder;
CellIRouter(
{required super.path,
super.pageBuilder,
super.children,
required this.cellBuilder});
class CellIRoute extends IRoute {
const CellIRoute({
required super.path,
super.pageBuilder,
super.children,
super.widget,
});
}
typedef CellBuilder = Widget Function(BuildContext context, Widget child);
typedef CellBuilder = Widget Function(BuildContext context,IRouteConfig config, CellIRoute cell);