This commit is contained in:
toly
2023-10-21 09:51:20 +08:00
parent d518b3c58a
commit 689e8d9fdb
49 changed files with 3006 additions and 64 deletions

View File

@@ -3,6 +3,7 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:iroute/13/04/app/navigation/router/iroute.dart';
import 'package:iroute/common/pages/stl_color_page.dart';
import '../../pages/color/color_page.dart';
import '../../pages/empty/empty_page.dart';
@@ -34,9 +35,13 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
return null;
}
late Completer<dynamic> completer;
final Map<String,Completer<dynamic>> _completerMap = {};
Completer<dynamic>? completer;
Future<dynamic> changePathForResult(String value) async{
completer = Completer();
Completer<dynamic> completer = Completer();
_completerMap[value] = completer;
path = value;
return completer.future;
}
@@ -78,30 +83,11 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
}
List<Page> _buildPageByPath(String path) {
if(path.startsWith('/color')){
return buildColorPages(path);
}
Widget? child;
List<Page> result = [];
if(path.startsWith('/color')){
result.add( FadeTransitionPage(
key: ValueKey('/color'),
child:const ColorPage(),
));
if(path == '/color/add'){
result.add( FadeTransitionPage(
key: ValueKey('/color/add'),
child:const ColorAddPage(),
));
}
return result;
}
if (path == kDestinationsPaths[0]) {
child = const ColorPage();
}
if (path == kDestinationsPaths[1]) {
child = const CounterPage();
}
@@ -119,6 +105,38 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
];
}
List<Page> buildColorPages(String path){
List<Page> result = [];
Uri uri = Uri.parse(path);
for (String segment in uri.pathSegments) {
if(segment == 'color'){
result.add( const FadeTransitionPage(
key: ValueKey('/color'),
child:ColorPage(),
));
}
if(segment =='detail'){
final Map<String, String> queryParams = uri.queryParameters;
String? selectedColor = queryParams['color'];
if (selectedColor != null) {
Color color = Color(int.parse(selectedColor, radix: 16));
result.add( FadeTransitionPage(
key: const ValueKey('/color/detail'),
child:StlColorPage(color: color),
));
}
}
if(segment == 'add'){
result.add( const FadeTransitionPage(
key: ValueKey('/color/add'),
child:ColorAddPage(),
));
}
}
return result;
}
@override
Future<bool> popRoute() async {
print('=======popRoute=========');
@@ -126,17 +144,28 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
}
bool _onPopPage(Route route, result) {
if(path == '/color/add'){
completer.complete(result);
path = '/color';
if(_completerMap.containsKey(path)){
_completerMap[path]?.complete(result);
_completerMap.remove(path);
}
path = backPath(path);
return route.didPop(result);
}
String backPath(String path){
Uri uri = Uri.parse(path);
if(uri.pathSegments.length==1) return path;
List<String> parts = List.of(uri.pathSegments)..removeLast();
return '/${parts.join('/')}';
}
@override
Future<void> setNewRoutePath(configuration) async {}
}
// class AppRouterDelegate extends RouterDelegate<String> with ChangeNotifier, PopNavigatorRouterDelegateMixin {
//
// List<String> _value = ['/'];