v8
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user