v10
This commit is contained in:
109
lib/v10/app/navigation/router/views/navigator_scope.dart
Normal file
109
lib/v10/app/navigation/router/views/navigator_scope.dart
Normal file
@@ -0,0 +1,109 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../iroute.dart';
|
||||
|
||||
import '../iroute_config.dart';
|
||||
|
||||
class NavigatorScope extends StatefulWidget {
|
||||
final IRouteNode node;
|
||||
final PopPageCallback onPopPage;
|
||||
final List<IRouteConfig> configs;
|
||||
final IRoutePageBuilder notFindPageBuilder;
|
||||
|
||||
const NavigatorScope({
|
||||
super.key,
|
||||
required this.node,
|
||||
required this.onPopPage,
|
||||
required this.configs,
|
||||
required this.notFindPageBuilder,
|
||||
});
|
||||
|
||||
@override
|
||||
State<NavigatorScope> createState() => _NavigatorScopeState();
|
||||
}
|
||||
|
||||
class _NavigatorScopeState extends State<NavigatorScope> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget content = Navigator(
|
||||
onPopPage: widget.onPopPage,
|
||||
pages: _buildPages(context, widget.configs),
|
||||
);
|
||||
|
||||
if(widget.node is CellIRoute){
|
||||
content = (widget.node as CellIRoute).cellBuilder(context,widget.configs.last,content);
|
||||
}
|
||||
return HeroControllerScope(
|
||||
controller: MaterialApp.createMaterialHeroController(),
|
||||
child: content,
|
||||
);
|
||||
}
|
||||
|
||||
List<Page> _buildPages(BuildContext context, List<IRouteConfig> configs) {
|
||||
IRouteConfig top = configs.last;
|
||||
List<IRouteConfig> bottoms =
|
||||
configs.sublist(0, configs.length - 1).toList();
|
||||
List<Page> pages = [];
|
||||
List<Page> topPages = _buildPageByPathFromTree(context, top);
|
||||
pages = _buildLivePageByPathList(context, bottoms, top, topPages);
|
||||
pages.addAll(topPages);
|
||||
return pages;
|
||||
}
|
||||
|
||||
List<Page> _buildLivePageByPathList(
|
||||
BuildContext context,
|
||||
List<IRouteConfig> paths,
|
||||
IRouteConfig curConfig,
|
||||
List<Page> curPages,
|
||||
) {
|
||||
List<Page> pages = [];
|
||||
if (paths.isNotEmpty) {
|
||||
for (IRouteConfig path in paths) {
|
||||
if (path != curConfig) {
|
||||
pages.addAll(_buildPageByPathFromTree(context, path));
|
||||
}
|
||||
}
|
||||
/// 去除和 curPages 中重复的界面
|
||||
pages.removeWhere((page) => curPages.map((e) => e.key).contains(page.key));
|
||||
}
|
||||
return pages;
|
||||
}
|
||||
|
||||
List<Page> _buildPageByPathFromTree(
|
||||
BuildContext context, IRouteConfig config) {
|
||||
List<Page> result = [];
|
||||
List<IRouteNode> iRoutes = widget.node.find(config.path);
|
||||
|
||||
if (iRoutes.isNotEmpty) {
|
||||
for (int i = 0; i < iRoutes.length; i++) {
|
||||
IRouteNode iroute = iRoutes[i];
|
||||
IRouteConfig fixConfig = config;
|
||||
|
||||
if(iroute.path!=config.uri.path){
|
||||
fixConfig = IRouteConfig(uri: Uri.parse(iroute.path));
|
||||
}
|
||||
|
||||
Page? page;
|
||||
if (iroute is NotFindNode) {
|
||||
page = widget.notFindPageBuilder(context, config);
|
||||
} else if (iroute is CellIRoute) {
|
||||
Widget scope = NavigatorScope(
|
||||
node: iroute,
|
||||
onPopPage: widget.onPopPage,
|
||||
configs: widget.configs,
|
||||
notFindPageBuilder: widget.notFindPageBuilder,
|
||||
);
|
||||
page = iroute.createCellPage(context, fixConfig, scope);
|
||||
} else {
|
||||
page = iroute.createPage(context, fixConfig);
|
||||
}
|
||||
if (page != null) {
|
||||
result.add(page);
|
||||
}
|
||||
if (iroute is CellIRoute) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
25
lib/v10/app/navigation/router/views/not_find_view.dart
Normal file
25
lib/v10/app/navigation/router/views/not_find_view.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class NotFindPage extends StatelessWidget {
|
||||
const NotFindPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Material(
|
||||
child: Center(
|
||||
child: Wrap(
|
||||
spacing: 16,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
direction: Axis.vertical,
|
||||
children: [
|
||||
Icon(Icons.nearby_error,size: 64, color: Colors.redAccent),
|
||||
Text(
|
||||
'404 Page Not Find',
|
||||
style: TextStyle(fontSize: 24, color: Colors.grey),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../app_router_delegate.dart';
|
||||
class RouteBackIndicator extends StatefulWidget {
|
||||
const RouteBackIndicator({super.key});
|
||||
|
||||
@override
|
||||
State<RouteBackIndicator> createState() => _RouteBackIndicatorState();
|
||||
}
|
||||
|
||||
class _RouteBackIndicatorState extends State<RouteBackIndicator> {
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
router.addListener(_onChange);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
router.removeListener(_onChange);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if(router.canPop){
|
||||
return MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
child: GestureDetector(
|
||||
onTap: router.backStack,
|
||||
child: Container(
|
||||
width: 26,
|
||||
height: 26,
|
||||
margin: EdgeInsets.only(right: 8),
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: Color(0xffE3E5E7),
|
||||
borderRadius: BorderRadius.circular(6)
|
||||
),
|
||||
child: Icon(Icons.arrow_back_ios_new,size: 14,)),
|
||||
),
|
||||
);
|
||||
}
|
||||
return SizedBox();
|
||||
}
|
||||
|
||||
void _onChange() {
|
||||
setState(() {
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user