Showing
25 changed files
with
376 additions
and
300 deletions
No preview for this file type
example_nav2/.gitignore
deleted
100644 → 0
| 1 | -# Miscellaneous | ||
| 2 | -*.class | ||
| 3 | -*.log | ||
| 4 | -*.pyc | ||
| 5 | -*.swp | ||
| 6 | -.DS_Store | ||
| 7 | -.atom/ | ||
| 8 | -.buildlog/ | ||
| 9 | -.history | ||
| 10 | -.svn/ | ||
| 11 | - | ||
| 12 | -# IntelliJ related | ||
| 13 | -*.iml | ||
| 14 | -*.ipr | ||
| 15 | -*.iws | ||
| 16 | -.idea/ | ||
| 17 | - | ||
| 18 | -# The .vscode folder contains launch configuration and tasks you configure in | ||
| 19 | -# VS Code which you may wish to be included in version control, so this line | ||
| 20 | -# is commented out by default. | ||
| 21 | -#.vscode/ | ||
| 22 | - | ||
| 23 | -# Flutter/Dart/Pub related | ||
| 24 | -**/doc/api/ | ||
| 25 | -**/ios/Flutter/.last_build_id | ||
| 26 | -.dart_tool/ | ||
| 27 | -.flutter-plugins | ||
| 28 | -.flutter-plugins-dependencies | ||
| 29 | -.packages | ||
| 30 | -.pub-cache/ | ||
| 31 | -.pub/ | ||
| 32 | -/build/ | ||
| 33 | - | ||
| 34 | -# Web related | ||
| 35 | -lib/generated_plugin_registrant.dart | ||
| 36 | - | ||
| 37 | -# Symbolication related | ||
| 38 | -app.*.symbols | ||
| 39 | - | ||
| 40 | -# Obfuscation related | ||
| 41 | -app.*.map.json | ||
| 42 | - | ||
| 43 | -# Android Studio will place build artifacts here | ||
| 44 | -/android/app/debug | ||
| 45 | -/android/app/profile | ||
| 46 | -/android/app/release | 
example_nav2/.metadata
deleted
100644 → 0
| 1 | -# This file tracks properties of this Flutter project. | ||
| 2 | -# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
| 3 | -# | ||
| 4 | -# This file should be version controlled and should not be manually edited. | ||
| 5 | - | ||
| 6 | -version: | ||
| 7 | - revision: b22742018b3edf16c6cadd7b76d9db5e7f9064b5 | ||
| 8 | - channel: stable | ||
| 9 | - | ||
| 10 | -project_type: app | 
example_nav2/android/.gitignore
deleted
100644 → 0
| 1 | +package io.flutter.plugins; | ||
| 2 | + | ||
| 3 | +import androidx.annotation.Keep; | ||
| 4 | +import androidx.annotation.NonNull; | ||
| 5 | +import io.flutter.Log; | ||
| 6 | + | ||
| 7 | +import io.flutter.embedding.engine.FlutterEngine; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * Generated file. Do not edit. | ||
| 11 | + * This file is generated by the Flutter tool based on the | ||
| 12 | + * plugins that support the Android platform. | ||
| 13 | + */ | ||
| 14 | +@Keep | ||
| 15 | +public final class GeneratedPluginRegistrant { | ||
| 16 | + private static final String TAG = "GeneratedPluginRegistrant"; | ||
| 17 | + public static void registerWith(@NonNull FlutterEngine flutterEngine) { | ||
| 18 | + } | ||
| 19 | +} | 
example_nav2/android/local.properties
0 → 100644
example_nav2/ios/.gitignore
deleted
100644 → 0
| 1 | -*.mode1v3 | ||
| 2 | -*.mode2v3 | ||
| 3 | -*.moved-aside | ||
| 4 | -*.pbxuser | ||
| 5 | -*.perspectivev3 | ||
| 6 | -**/*sync/ | ||
| 7 | -.sconsign.dblite | ||
| 8 | -.tags* | ||
| 9 | -**/.vagrant/ | ||
| 10 | -**/DerivedData/ | ||
| 11 | -Icon? | ||
| 12 | -**/Pods/ | ||
| 13 | -**/.symlinks/ | ||
| 14 | -profile | ||
| 15 | -xcuserdata | ||
| 16 | -**/.generated/ | ||
| 17 | -Flutter/App.framework | ||
| 18 | -Flutter/Flutter.framework | ||
| 19 | -Flutter/Flutter.podspec | ||
| 20 | -Flutter/Generated.xcconfig | ||
| 21 | -Flutter/ephemeral/ | ||
| 22 | -Flutter/app.flx | ||
| 23 | -Flutter/app.zip | ||
| 24 | -Flutter/flutter_assets/ | ||
| 25 | -Flutter/flutter_export_environment.sh | ||
| 26 | -ServiceDefinitions.json | ||
| 27 | -Runner/GeneratedPluginRegistrant.* | ||
| 28 | - | ||
| 29 | -# Exceptions to above rules. | ||
| 30 | -!default.mode1v3 | ||
| 31 | -!default.mode2v3 | ||
| 32 | -!default.pbxuser | ||
| 33 | -!default.perspectivev3 | 
example_nav2/ios/Flutter/Generated.xcconfig
0 → 100644
| 1 | +// This is a generated file; do not edit or check into version control. | ||
| 2 | +FLUTTER_ROOT=/Users/jonatasborges/flutter | ||
| 3 | +FLUTTER_APPLICATION_PATH=/Users/jonatasborges/consertar/getx/example_nav2 | ||
| 4 | +COCOAPODS_PARALLEL_CODE_SIGN=true | ||
| 5 | +FLUTTER_TARGET=/Users/jonatasborges/consertar/getx/example_nav2/lib/main.dart | ||
| 6 | +FLUTTER_BUILD_DIR=build | ||
| 7 | +FLUTTER_BUILD_NAME=1.0.0 | ||
| 8 | +FLUTTER_BUILD_NUMBER=1 | ||
| 9 | +EXCLUDED_ARCHS[sdk=iphonesimulator*]=i386 | ||
| 10 | +DART_DEFINES=Zmx1dHRlci5pbnNwZWN0b3Iuc3RydWN0dXJlZEVycm9ycz10cnVl,RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ== | ||
| 11 | +DART_OBFUSCATION=false | ||
| 12 | +TRACK_WIDGET_CREATION=true | ||
| 13 | +TREE_SHAKE_ICONS=false | ||
| 14 | +PACKAGE_CONFIG=/Users/jonatasborges/consertar/getx/example_nav2/.dart_tool/package_config.json | 
| 1 | +#!/bin/sh | ||
| 2 | +# This is a generated file; do not edit or check into version control. | ||
| 3 | +export "FLUTTER_ROOT=/Users/jonatasborges/flutter" | ||
| 4 | +export "FLUTTER_APPLICATION_PATH=/Users/jonatasborges/consertar/getx/example_nav2" | ||
| 5 | +export "COCOAPODS_PARALLEL_CODE_SIGN=true" | ||
| 6 | +export "FLUTTER_TARGET=/Users/jonatasborges/consertar/getx/example_nav2/lib/main.dart" | ||
| 7 | +export "FLUTTER_BUILD_DIR=build" | ||
| 8 | +export "FLUTTER_BUILD_NAME=1.0.0" | ||
| 9 | +export "FLUTTER_BUILD_NUMBER=1" | ||
| 10 | +export "DART_DEFINES=Zmx1dHRlci5pbnNwZWN0b3Iuc3RydWN0dXJlZEVycm9ycz10cnVl,RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==" | ||
| 11 | +export "DART_OBFUSCATION=false" | ||
| 12 | +export "TRACK_WIDGET_CREATION=true" | ||
| 13 | +export "TREE_SHAKE_ICONS=false" | ||
| 14 | +export "PACKAGE_CONFIG=/Users/jonatasborges/consertar/getx/example_nav2/.dart_tool/package_config.json" | 
| 1 | +// | ||
| 2 | +// Generated file. Do not edit. | ||
| 3 | +// | ||
| 4 | + | ||
| 5 | +// clang-format off | ||
| 6 | + | ||
| 7 | +#ifndef GeneratedPluginRegistrant_h | ||
| 8 | +#define GeneratedPluginRegistrant_h | ||
| 9 | + | ||
| 10 | +#import <Flutter/Flutter.h> | ||
| 11 | + | ||
| 12 | +NS_ASSUME_NONNULL_BEGIN | ||
| 13 | + | ||
| 14 | +@interface GeneratedPluginRegistrant : NSObject | ||
| 15 | ++ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry; | ||
| 16 | +@end | ||
| 17 | + | ||
| 18 | +NS_ASSUME_NONNULL_END | ||
| 19 | +#endif /* GeneratedPluginRegistrant_h */ | 
| @@ -31,7 +31,9 @@ class LoginView extends GetView<LoginController> { | @@ -31,7 +31,9 @@ class LoginView extends GetView<LoginController> { | ||
| 31 | ), | 31 | ), | 
| 32 | onPressed: () { | 32 | onPressed: () { | 
| 33 | AuthService.to.login(); | 33 | AuthService.to.login(); | 
| 34 | + | ||
| 34 | final thenTo = context.params['then']; | 35 | final thenTo = context.params['then']; | 
| 36 | + print(context.navigation.currentConfiguration?.route?.parameters); | ||
| 35 | Get.offNamed(thenTo ?? Routes.home); | 37 | Get.offNamed(thenTo ?? Routes.home); | 
| 36 | }, | 38 | }, | 
| 37 | ), | 39 | ), | 
| @@ -15,10 +15,11 @@ class ProductsView extends GetView<ProductsController> { | @@ -15,10 +15,11 @@ class ProductsView extends GetView<ProductsController> { | ||
| 15 | ), | 15 | ), | 
| 16 | body: Column( | 16 | body: Column( | 
| 17 | children: [ | 17 | children: [ | 
| 18 | - Hero( | ||
| 19 | - tag: 'heroLogo', | ||
| 20 | - child: const FlutterLogo(), | ||
| 21 | - ), | 18 | + // Hero( | 
| 19 | + // tag: 'heroLogo', | ||
| 20 | + // child: | ||
| 21 | + const FlutterLogo(), | ||
| 22 | + // ), | ||
| 22 | Expanded( | 23 | Expanded( | 
| 23 | child: Obx( | 24 | child: Obx( | 
| 24 | () => RefreshIndicator( | 25 | () => RefreshIndicator( | 
example_nav2/windows/.gitignore
deleted
100644 → 0
| 1 | -flutter/ephemeral/ | ||
| 2 | - | ||
| 3 | -# Visual Studio user-specific files. | ||
| 4 | -*.suo | ||
| 5 | -*.user | ||
| 6 | -*.userosscache | ||
| 7 | -*.sln.docstates | ||
| 8 | - | ||
| 9 | -# Visual Studio build-related files. | ||
| 10 | -x64/ | ||
| 11 | -x86/ | ||
| 12 | - | ||
| 13 | -# Visual Studio cache files | ||
| 14 | -# files ending in .cache can be ignored | ||
| 15 | -*.[Cc]ache | ||
| 16 | -# but keep track of directories ending in .cache | ||
| 17 | -!*.[Cc]ache/ | 
| @@ -5,6 +5,9 @@ | @@ -5,6 +5,9 @@ | ||
| 5 | list(APPEND FLUTTER_PLUGIN_LIST | 5 | list(APPEND FLUTTER_PLUGIN_LIST | 
| 6 | ) | 6 | ) | 
| 7 | 7 | ||
| 8 | +list(APPEND FLUTTER_FFI_PLUGIN_LIST | ||
| 9 | +) | ||
| 10 | + | ||
| 8 | set(PLUGIN_BUNDLED_LIBRARIES) | 11 | set(PLUGIN_BUNDLED_LIBRARIES) | 
| 9 | 12 | ||
| 10 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) | 13 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) | 
| @@ -13,3 +16,8 @@ foreach(plugin ${FLUTTER_PLUGIN_LIST}) | @@ -13,3 +16,8 @@ foreach(plugin ${FLUTTER_PLUGIN_LIST}) | ||
| 13 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>) | 16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>) | 
| 14 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) | 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) | 
| 15 | endforeach(plugin) | 18 | endforeach(plugin) | 
| 19 | + | ||
| 20 | +foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) | ||
| 21 | + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) | ||
| 22 | + list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) | ||
| 23 | +endforeach(ffi_plugin) | 
| @@ -45,7 +45,7 @@ class GetPage<T> extends Page<T> { | @@ -45,7 +45,7 @@ class GetPage<T> extends Page<T> { | ||
| 45 | 45 | ||
| 46 | final List<GetPage> children; | 46 | final List<GetPage> children; | 
| 47 | final List<GetMiddleware>? middlewares; | 47 | final List<GetMiddleware>? middlewares; | 
| 48 | - final PathDecoded path; | 48 | + // final PathDecoded path; | 
| 49 | final GetPage? unknownRoute; | 49 | final GetPage? unknownRoute; | 
| 50 | final bool showCupertinoParallax; | 50 | final bool showCupertinoParallax; | 
| 51 | 51 | ||
| @@ -82,7 +82,7 @@ class GetPage<T> extends Page<T> { | @@ -82,7 +82,7 @@ class GetPage<T> extends Page<T> { | ||
| 82 | PreventDuplicateHandlingMode.reorderRoutes, | 82 | PreventDuplicateHandlingMode.reorderRoutes, | 
| 83 | this.completer, | 83 | this.completer, | 
| 84 | LocalKey? key, | 84 | LocalKey? key, | 
| 85 | - }) : path = _nameToRegex(name), | 85 | + }) : // path = _nameToRegex(name), | 
| 86 | assert(name.startsWith('/'), | 86 | assert(name.startsWith('/'), | 
| 87 | 'It is necessary to start route name [$name] with a slash: /$name'), | 87 | 'It is necessary to start route name [$name] with a slash: /$name'), | 
| 88 | super( | 88 | super( | 
| @@ -168,26 +168,26 @@ class GetPage<T> extends Page<T> { | @@ -168,26 +168,26 @@ class GetPage<T> extends Page<T> { | ||
| 168 | return _page; | 168 | return _page; | 
| 169 | } | 169 | } | 
| 170 | 170 | ||
| 171 | - static PathDecoded _nameToRegex(String path) { | ||
| 172 | - var keys = <String?>[]; | 171 | + // static PathDecoded _nameToRegex(String path) { | 
| 172 | + // var keys = <String?>[]; | ||
| 173 | 173 | ||
| 174 | - String _replace(Match pattern) { | ||
| 175 | - var buffer = StringBuffer('(?:'); | 174 | + // String _replace(Match pattern) { | 
| 175 | + // var buffer = StringBuffer('(?:'); | ||
| 176 | 176 | ||
| 177 | - if (pattern[1] != null) buffer.write('.'); | ||
| 178 | - buffer.write('([\\w%+-._~!\$&\'()*,;=:@]+))'); | ||
| 179 | - if (pattern[3] != null) buffer.write('?'); | 177 | + // if (pattern[1] != null) buffer.write('.'); | 
| 178 | + // buffer.write('([\\w%+-._~!\$&\'()*,;=:@]+))'); | ||
| 179 | + // if (pattern[3] != null) buffer.write('?'); | ||
| 180 | 180 | ||
| 181 | - keys.add(pattern[2]); | ||
| 182 | - return "$buffer"; | ||
| 183 | - } | 181 | + // keys.add(pattern[2]); | 
| 182 | + // return "$buffer"; | ||
| 183 | + // } | ||
| 184 | 184 | ||
| 185 | - var stringPath = '$path/?' | ||
| 186 | - .replaceAllMapped(RegExp(r'(\.)?:(\w+)(\?)?'), _replace) | ||
| 187 | - .replaceAll('//', '/'); | 185 | + // var stringPath = '$path/?' | 
| 186 | + // .replaceAllMapped(RegExp(r'(\.)?:(\w+)(\?)?'), _replace) | ||
| 187 | + // .replaceAll('//', '/'); | ||
| 188 | 188 | ||
| 189 | - return PathDecoded(RegExp('^$stringPath\$'), keys); | ||
| 190 | - } | 189 | + // return PathDecoded(RegExp('^$stringPath\$'), keys); | 
| 190 | + // } | ||
| 191 | 191 | ||
| 192 | @override | 192 | @override | 
| 193 | bool operator ==(Object other) { | 193 | bool operator ==(Object other) { | 
| @@ -205,20 +205,20 @@ class GetPage<T> extends Page<T> { | @@ -205,20 +205,20 @@ class GetPage<T> extends Page<T> { | ||
| 205 | } | 205 | } | 
| 206 | } | 206 | } | 
| 207 | 207 | ||
| 208 | -@immutable | ||
| 209 | -class PathDecoded { | ||
| 210 | - final RegExp regex; | ||
| 211 | - final List<String?> keys; | ||
| 212 | - const PathDecoded(this.regex, this.keys); | 208 | +// @immutable | 
| 209 | +// class PathDecoded { | ||
| 210 | +// final RegExp regex; | ||
| 211 | +// final List<String?> keys; | ||
| 212 | +// const PathDecoded(this.regex, this.keys); | ||
| 213 | 213 | ||
| 214 | - @override | ||
| 215 | - int get hashCode => regex.hashCode; | 214 | +// @override | 
| 215 | +// int get hashCode => regex.hashCode; | ||
| 216 | 216 | ||
| 217 | - @override | ||
| 218 | - bool operator ==(Object other) { | ||
| 219 | - if (identical(this, other)) return true; | 217 | +// @override | 
| 218 | +// bool operator ==(Object other) { | ||
| 219 | +// if (identical(this, other)) return true; | ||
| 220 | 220 | ||
| 221 | - return other is PathDecoded && | ||
| 222 | - other.regex == regex; // && listEquals(other.keys, keys); | ||
| 223 | - } | ||
| 224 | -} | 221 | +// return other is PathDecoded && | 
| 222 | +// other.regex == regex; // && listEquals(other.keys, keys); | ||
| 223 | +// } | ||
| 224 | +// } | 
| @@ -26,28 +26,31 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -26,28 +26,31 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
| 26 | 26 | ||
| 27 | List<RouteDecoder> get activePages => _activePages; | 27 | List<RouteDecoder> get activePages => _activePages; | 
| 28 | 28 | ||
| 29 | - final _routeTree = ParseRouteTree(routes: []); | 29 | + final _routeTree = ParseRouteTree(); | 
| 30 | 30 | ||
| 31 | - List<GetPage> get registeredRoutes => _routeTree.routes; | 31 | + final List<GetPage> _routes = []; | 
| 32 | + | ||
| 33 | + List<GetPage> get registeredRoutes => _routes; | ||
| 32 | 34 | ||
| 33 | void addPages(List<GetPage> getPages) { | 35 | void addPages(List<GetPage> getPages) { | 
| 34 | - _routeTree.addRoutes(getPages); | 36 | + _routes.addRoutes(getPages); | 
| 35 | } | 37 | } | 
| 36 | 38 | ||
| 37 | void clearRouteTree() { | 39 | void clearRouteTree() { | 
| 38 | - _routeTree.routes.clear(); | 40 | + _routes.clear(); | 
| 39 | } | 41 | } | 
| 40 | 42 | ||
| 41 | void addPage(GetPage getPage) { | 43 | void addPage(GetPage getPage) { | 
| 42 | - _routeTree.addRoute(getPage); | 44 | + _routes.addRoute(getPage); | 
| 43 | } | 45 | } | 
| 44 | 46 | ||
| 45 | void removePage(GetPage getPage) { | 47 | void removePage(GetPage getPage) { | 
| 46 | - _routeTree.removeRoute(getPage); | 48 | + _routes.removeRoute(getPage); | 
| 47 | } | 49 | } | 
| 48 | 50 | ||
| 49 | - RouteDecoder matchRoute(String name, {PageSettings? arguments}) { | ||
| 50 | - return _routeTree.matchRoute(name, arguments: arguments); | 51 | + RouteDecoder? matchRoute(String name, {PageSettings? arguments}) { | 
| 52 | + final settings = _buildPageSettings(name, arguments); | ||
| 53 | + return _getRouteDecoder(settings); | ||
| 51 | } | 54 | } | 
| 52 | 55 | ||
| 53 | // GlobalKey<NavigatorState> get navigatorKey => Get.key; | 56 | // GlobalKey<NavigatorState> get navigatorKey => Get.key; | 
| @@ -138,7 +141,9 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -138,7 +141,9 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
| 138 | } | 141 | } | 
| 139 | 142 | ||
| 140 | Map<String, String> get parameters { | 143 | Map<String, String> get parameters { | 
| 141 | - return currentConfiguration?.pageSettings?.params ?? {}; | 144 | + return currentConfiguration?.route?.parameters ?? | 
| 145 | + // currentConfiguration?.pageSettings?.params ?? | ||
| 146 | + {}; | ||
| 142 | } | 147 | } | 
| 143 | 148 | ||
| 144 | PageSettings? get pageSettings { | 149 | PageSettings? get pageSettings { | 
| @@ -379,14 +384,14 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -379,14 +384,14 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
| 379 | preventDuplicateHandlingMode: preventDuplicateHandlingMode, | 384 | preventDuplicateHandlingMode: preventDuplicateHandlingMode, | 
| 380 | ); | 385 | ); | 
| 381 | 386 | ||
| 382 | - _routeTree.addRoute(getPage); | 387 | + _routes.addRoute(getPage); | 
| 383 | final args = _buildPageSettings(routeName, arguments); | 388 | final args = _buildPageSettings(routeName, arguments); | 
| 384 | final route = _getRouteDecoder<T>(args); | 389 | final route = _getRouteDecoder<T>(args); | 
| 385 | final result = await _push<T>( | 390 | final result = await _push<T>( | 
| 386 | route!, | 391 | route!, | 
| 387 | rebuildStack: rebuildStack, | 392 | rebuildStack: rebuildStack, | 
| 388 | ); | 393 | ); | 
| 389 | - _routeTree.removeRoute(getPage); | 394 | + _routes.removeRoute(getPage); | 
| 390 | return result; | 395 | return result; | 
| 391 | } | 396 | } | 
| 392 | 397 | ||
| @@ -623,7 +628,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -623,7 +628,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
| 623 | 628 | ||
| 624 | Future<T?> _replace<T>(PageSettings arguments, GetPage<T> page) async { | 629 | Future<T?> _replace<T>(PageSettings arguments, GetPage<T> page) async { | 
| 625 | final index = _activePages.length > 1 ? _activePages.length - 1 : 0; | 630 | final index = _activePages.length > 1 ? _activePages.length - 1 : 0; | 
| 626 | - _routeTree.addRoute(page); | 631 | + _routes.addRoute(page); | 
| 627 | 632 | ||
| 628 | final activePage = _getRouteDecoder(arguments); | 633 | final activePage = _getRouteDecoder(arguments); | 
| 629 | 634 | ||
| @@ -633,7 +638,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -633,7 +638,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
| 633 | 638 | ||
| 634 | notifyListeners(); | 639 | notifyListeners(); | 
| 635 | final result = await activePage.route?.completer?.future as Future<T?>?; | 640 | final result = await activePage.route?.completer?.future as Future<T?>?; | 
| 636 | - _routeTree.removeRoute(page); | 641 | + _routes.removeRoute(page); | 
| 637 | 642 | ||
| 638 | return result; | 643 | return result; | 
| 639 | } | 644 | } | 
| @@ -678,7 +683,8 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -678,7 +683,8 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
| 678 | page = uri.toString(); | 683 | page = uri.toString(); | 
| 679 | } | 684 | } | 
| 680 | 685 | ||
| 681 | - final decoder = _routeTree.matchRoute(page, arguments: arguments); | 686 | + final decoder = | 
| 687 | + _routeTree.matchRoute(registeredRoutes, page, arguments: arguments); | ||
| 682 | final route = decoder.route; | 688 | final route = decoder.route; | 
| 683 | if (route == null) return null; | 689 | if (route == null) return null; | 
| 684 | 690 | ||
| @@ -701,7 +707,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -701,7 +707,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
| 701 | completer: _activePages.isEmpty ? null : Completer(), | 707 | completer: _activePages.isEmpty ? null : Completer(), | 
| 702 | arguments: arguments, | 708 | arguments: arguments, | 
| 703 | parameters: parameters, | 709 | parameters: parameters, | 
| 704 | - key: ValueKey(arguments.name), | 710 | + // key: ValueKey(arguments.name), | 
| 705 | ); | 711 | ); | 
| 706 | 712 | ||
| 707 | return decoder; | 713 | return decoder; | 
| 1 | +import 'dart:math'; | ||
| 2 | + | ||
| 1 | import 'package:flutter/foundation.dart'; | 3 | import 'package:flutter/foundation.dart'; | 
| 2 | 4 | ||
| 3 | import '../../../route_manager.dart'; | 5 | import '../../../route_manager.dart'; | 
| @@ -16,10 +18,11 @@ class RouteDecoder { | @@ -16,10 +18,11 @@ class RouteDecoder { | ||
| 16 | final args = PageSettings(uri); | 18 | final args = PageSettings(uri); | 
| 17 | final decoder = (Get.rootController.routerDelegate as GetDelegate) | 19 | final decoder = (Get.rootController.routerDelegate as GetDelegate) | 
| 18 | .matchRoute(location, arguments: args); | 20 | .matchRoute(location, arguments: args); | 
| 19 | - decoder.route = decoder.route?.copy( | 21 | + | 
| 22 | + decoder!.route = decoder.route?.copy( | ||
| 20 | completer: null, | 23 | completer: null, | 
| 21 | arguments: args, | 24 | arguments: args, | 
| 22 | - parameters: args.params, | 25 | + parameters: decoder.parameters, | 
| 23 | ); | 26 | ); | 
| 24 | return decoder; | 27 | return decoder; | 
| 25 | } | 28 | } | 
| @@ -78,96 +81,62 @@ class RouteDecoder { | @@ -78,96 +81,62 @@ class RouteDecoder { | ||
| 78 | } | 81 | } | 
| 79 | 82 | ||
| 80 | class ParseRouteTree { | 83 | class ParseRouteTree { | 
| 81 | - ParseRouteTree({ | ||
| 82 | - required this.routes, | ||
| 83 | - }); | ||
| 84 | - | ||
| 85 | - final List<GetPage> routes; | ||
| 86 | - | ||
| 87 | - RouteDecoder matchRoute(String name, {PageSettings? arguments}) { | ||
| 88 | - final uri = Uri.parse(name); | ||
| 89 | - // /home/profile/123 => home,profile,123 => /,/home,/home/profile,/home/profile/123 | ||
| 90 | - final split = uri.path.split('/').where((element) => element.isNotEmpty); | ||
| 91 | - var curPath = '/'; | ||
| 92 | - final cumulativePaths = <String>[ | ||
| 93 | - '/', | ||
| 94 | - ]; | ||
| 95 | - for (var item in split) { | ||
| 96 | - if (curPath.endsWith('/')) { | ||
| 97 | - curPath += item; | ||
| 98 | - } else { | ||
| 99 | - curPath += '/$item'; | 84 | + RouteDecoder matchRoute(List<GetPage> routes, String name, | 
| 85 | + {PageSettings? arguments}) { | ||
| 86 | + final args = arguments ?? PageSettings(Uri.parse(name)); | ||
| 87 | + final treeBranch = routes | ||
| 88 | + .where((e) => RouteParser.hasMatch( | ||
| 89 | + pushedRoute: name, routeName: e.name, withChildren: true)) | ||
| 90 | + .map((e) { | ||
| 91 | + final parameters = | ||
| 92 | + RouteParser.parse(pushedRoute: name, routeName: e.name).parameters; | ||
| 93 | + final routeParams = e.parameters; | ||
| 94 | + if (routeParams != null) { | ||
| 95 | + parameters.addAll(routeParams); | ||
| 100 | } | 96 | } | 
| 101 | - cumulativePaths.add(curPath); | ||
| 102 | - } | ||
| 103 | - | ||
| 104 | - final treeBranch = cumulativePaths | ||
| 105 | - .map((e) => MapEntry(e, _findRoute(e))) | ||
| 106 | - .where((element) => element.value != null) | ||
| 107 | - | ||
| 108 | - ///Prevent page be disposed | ||
| 109 | - .map((e) => MapEntry(e.key, e.value!.copy(key: ValueKey(e.key)))) | ||
| 110 | - .toList(); | ||
| 111 | - | ||
| 112 | - final params = Map<String, String>.from(uri.queryParameters); | ||
| 113 | - if (treeBranch.isNotEmpty) { | ||
| 114 | - //route is found, do further parsing to get nested query params | ||
| 115 | - final lastRoute = treeBranch.last; | ||
| 116 | - final parsedParams = _parseParams(name, lastRoute.value.path); | ||
| 117 | - if (parsedParams.isNotEmpty) { | ||
| 118 | - params.addAll(parsedParams); | 97 | + if (args.params.isNotEmpty) { | 
| 98 | + parameters.addAll(args.params); | ||
| 119 | } | 99 | } | 
| 120 | - //copy parameters to all pages. | ||
| 121 | - final mappedTreeBranch = treeBranch | ||
| 122 | - .map( | ||
| 123 | - (e) => e.value.copy( | ||
| 124 | - parameters: { | ||
| 125 | - if (e.value.parameters != null) ...e.value.parameters!, | ||
| 126 | - ...params, | ||
| 127 | - }, | ||
| 128 | - name: e.key, | ||
| 129 | - ), | ||
| 130 | - ) | ||
| 131 | - .toList(); | ||
| 132 | - arguments?.params.clear(); | ||
| 133 | - arguments?.params.addAll(params); | ||
| 134 | - return RouteDecoder( | ||
| 135 | - mappedTreeBranch, | ||
| 136 | - arguments, | ||
| 137 | - ); | ||
| 138 | - } | ||
| 139 | 100 | ||
| 140 | - arguments?.params.clear(); | ||
| 141 | - arguments?.params.addAll(params); | 101 | + args.params.clear(); | 
| 102 | + args.params.addAll(parameters); | ||
| 103 | + | ||
| 104 | + return e.copy( | ||
| 105 | + settings: args, | ||
| 106 | + parameters: parameters, | ||
| 107 | + ); | ||
| 108 | + }).toList(); | ||
| 142 | 109 | ||
| 143 | //route not found | 110 | //route not found | 
| 144 | return RouteDecoder( | 111 | return RouteDecoder( | 
| 145 | - treeBranch.map((e) => e.value).toList(), | 112 | + treeBranch, | 
| 146 | arguments, | 113 | arguments, | 
| 147 | ); | 114 | ); | 
| 148 | } | 115 | } | 
| 116 | +} | ||
| 149 | 117 | ||
| 150 | - void addRoutes<T>(List<GetPage<T>> getPages) { | 118 | +extension FirstWhereOrNullExt<T> on List<GetPage<T>> { | 
| 119 | + void addRoutes(List<GetPage<T>> getPages) { | ||
| 151 | for (final route in getPages) { | 120 | for (final route in getPages) { | 
| 152 | addRoute(route); | 121 | addRoute(route); | 
| 153 | } | 122 | } | 
| 154 | } | 123 | } | 
| 155 | 124 | ||
| 156 | - void removeRoutes<T>(List<GetPage<T>> getPages) { | 125 | + void removeRoutes(List<GetPage<T>> getPages) { | 
| 157 | for (final route in getPages) { | 126 | for (final route in getPages) { | 
| 158 | removeRoute(route); | 127 | removeRoute(route); | 
| 159 | } | 128 | } | 
| 160 | } | 129 | } | 
| 161 | 130 | ||
| 162 | - void removeRoute<T>(GetPage<T> route) { | ||
| 163 | - routes.remove(route); | 131 | + void removeRoute(GetPage<T> route) { | 
| 132 | + remove(route); | ||
| 164 | for (var page in _flattenPage(route)) { | 133 | for (var page in _flattenPage(route)) { | 
| 165 | removeRoute(page); | 134 | removeRoute(page); | 
| 166 | } | 135 | } | 
| 167 | } | 136 | } | 
| 168 | 137 | ||
| 169 | - void addRoute<T>(GetPage<T> route) { | ||
| 170 | - routes.add(route); | 138 | + void addRoute(GetPage<T> route) { | 
| 139 | + add(route); | ||
| 171 | 140 | ||
| 172 | // Add Page children. | 141 | // Add Page children. | 
| 173 | for (var page in _flattenPage(route)) { | 142 | for (var page in _flattenPage(route)) { | 
| @@ -175,14 +144,15 @@ class ParseRouteTree { | @@ -175,14 +144,15 @@ class ParseRouteTree { | ||
| 175 | } | 144 | } | 
| 176 | } | 145 | } | 
| 177 | 146 | ||
| 178 | - List<GetPage> _flattenPage(GetPage route) { | ||
| 179 | - final result = <GetPage>[]; | 147 | + List<GetPage<T>> _flattenPage(GetPage<T> route) { | 
| 148 | + final result = <GetPage<T>>[]; | ||
| 180 | if (route.children.isEmpty) { | 149 | if (route.children.isEmpty) { | 
| 181 | return result; | 150 | return result; | 
| 182 | } | 151 | } | 
| 183 | 152 | ||
| 184 | - final parentPath = route.name; | 153 | + var parentPathOld = route.name; | 
| 185 | for (var page in route.children) { | 154 | for (var page in route.children) { | 
| 155 | + final parentPath2 = (parentPathOld + page.name).replaceAll(r'//', '/'); | ||
| 186 | // Add Parent middlewares to children | 156 | // Add Parent middlewares to children | 
| 187 | final parentMiddlewares = [ | 157 | final parentMiddlewares = [ | 
| 188 | if (page.middlewares != null) ...page.middlewares!, | 158 | if (page.middlewares != null) ...page.middlewares!, | 
| @@ -190,66 +160,48 @@ class ParseRouteTree { | @@ -190,66 +160,48 @@ class ParseRouteTree { | ||
| 190 | ]; | 160 | ]; | 
| 191 | result.add( | 161 | result.add( | 
| 192 | _addChild( | 162 | _addChild( | 
| 193 | - page, | ||
| 194 | - parentPath, | 163 | + page as GetPage<T>, | 
| 164 | + parentPath2, | ||
| 195 | parentMiddlewares, | 165 | parentMiddlewares, | 
| 196 | ), | 166 | ), | 
| 197 | ); | 167 | ); | 
| 198 | 168 | ||
| 199 | final children = _flattenPage(page); | 169 | final children = _flattenPage(page); | 
| 200 | - for (var child in children) { | ||
| 201 | - result.add(_addChild( | ||
| 202 | - child, | ||
| 203 | - parentPath, | ||
| 204 | - [ | ||
| 205 | - ...parentMiddlewares, | ||
| 206 | - if (child.middlewares != null) ...child.middlewares!, | ||
| 207 | - ], | ||
| 208 | - )); | ||
| 209 | - } | 170 | + // for (var child in children) { | 
| 171 | + // final parentPath = (parentPath2 + page.name).replaceAll(r'//', '/'); | ||
| 172 | + // result.add(_addChild( | ||
| 173 | + // child, | ||
| 174 | + // parentPath, | ||
| 175 | + // [ | ||
| 176 | + // ...parentMiddlewares, | ||
| 177 | + // if (child.middlewares != null) ...child.middlewares!, | ||
| 178 | + // ], | ||
| 179 | + // )); | ||
| 180 | + // } | ||
| 210 | } | 181 | } | 
| 211 | return result; | 182 | return result; | 
| 212 | } | 183 | } | 
| 213 | 184 | ||
| 214 | /// Change the Path for a [GetPage] | 185 | /// Change the Path for a [GetPage] | 
| 215 | - GetPage _addChild( | ||
| 216 | - GetPage origin, String parentPath, List<GetMiddleware> middlewares) { | 186 | + GetPage<T> _addChild( | 
| 187 | + GetPage<T> origin, String parentPath, List<GetMiddleware> middlewares) { | ||
| 217 | return origin.copy( | 188 | return origin.copy( | 
| 218 | middlewares: middlewares, | 189 | middlewares: middlewares, | 
| 219 | - name: (parentPath + origin.name).replaceAll(r'//', '/'), | ||
| 220 | - // key: | 190 | + name: parentPath, | 
| 191 | + key: ValueKey(parentPath), | ||
| 221 | ); | 192 | ); | 
| 222 | } | 193 | } | 
| 223 | 194 | ||
| 224 | - GetPage? _findRoute(String name) { | ||
| 225 | - final value = routes.firstWhereOrNull( | ||
| 226 | - (route) => route.path.regex.hasMatch(name), | ||
| 227 | - ); | 195 | + // GetPage<T>? _findRoute(String name) { | 
| 196 | + // final value = firstWhereOrNull( | ||
| 197 | + // (route) => route.path.regex.hasMatch(name), | ||
| 198 | + // ); | ||
| 228 | 199 | ||
| 229 | - return value; | ||
| 230 | - } | ||
| 231 | - | ||
| 232 | - Map<String, String> _parseParams(String path, PathDecoded routePath) { | ||
| 233 | - final params = <String, String>{}; | ||
| 234 | - var idx = path.indexOf('?'); | ||
| 235 | - if (idx > -1) { | ||
| 236 | - path = path.substring(0, idx); | ||
| 237 | - final uri = Uri.tryParse(path); | ||
| 238 | - if (uri != null) { | ||
| 239 | - params.addAll(uri.queryParameters); | ||
| 240 | - } | ||
| 241 | - } | ||
| 242 | - var paramsMatch = routePath.regex.firstMatch(path); | ||
| 243 | - | ||
| 244 | - for (var i = 0; i < routePath.keys.length; i++) { | ||
| 245 | - var param = Uri.decodeQueryComponent(paramsMatch![i + 1]!); | ||
| 246 | - params[routePath.keys[i]!] = param; | ||
| 247 | - } | ||
| 248 | - return params; | ||
| 249 | - } | 200 | + // return value; | 
| 201 | + // } | ||
| 250 | } | 202 | } | 
| 251 | 203 | ||
| 252 | -extension FirstWhereOrNullExt<T> on List<T> { | 204 | +extension FirstWhereExt<T> on List<T> { | 
| 253 | /// The first element satisfying [test], or `null` if there are none. | 205 | /// The first element satisfying [test], or `null` if there are none. | 
| 254 | T? firstWhereOrNull(bool Function(T element) test) { | 206 | T? firstWhereOrNull(bool Function(T element) test) { | 
| 255 | for (var element in this) { | 207 | for (var element in this) { | 
| @@ -258,3 +210,96 @@ extension FirstWhereOrNullExt<T> on List<T> { | @@ -258,3 +210,96 @@ extension FirstWhereOrNullExt<T> on List<T> { | ||
| 258 | return null; | 210 | return null; | 
| 259 | } | 211 | } | 
| 260 | } | 212 | } | 
| 213 | + | ||
| 214 | +class RouteParser { | ||
| 215 | + static RouteParser parse({required String pushedRoute, required routeName}) { | ||
| 216 | + final data = RouteParser(pushedRoute: pushedRoute, routeName: routeName); | ||
| 217 | + | ||
| 218 | + final minLength = | ||
| 219 | + min(data.originalPathSegments.length, data.newPathSegments.length); | ||
| 220 | + | ||
| 221 | + for (var i = 0; i < minLength; i++) { | ||
| 222 | + final originalPathSegment = data.originalPathSegments[i]; | ||
| 223 | + final newPathSegment = Uri.parse(data.newPathSegments[i]); | ||
| 224 | + | ||
| 225 | + if (originalPathSegment.startsWith(':')) { | ||
| 226 | + final key = originalPathSegment.replaceFirst(':', ''); | ||
| 227 | + data.parameters[key] = newPathSegment.toString(); | ||
| 228 | + data.matchingSegments.add(newPathSegment); | ||
| 229 | + continue; | ||
| 230 | + } | ||
| 231 | + | ||
| 232 | + if (newPathSegment.path == originalPathSegment) { | ||
| 233 | + data.matchingSegments.add(newPathSegment); | ||
| 234 | + data.parameters.addAll(data.newRouteUri.queryParameters); | ||
| 235 | + | ||
| 236 | + continue; | ||
| 237 | + } else { | ||
| 238 | + break; | ||
| 239 | + } | ||
| 240 | + } | ||
| 241 | + | ||
| 242 | + return data; | ||
| 243 | + } | ||
| 244 | + | ||
| 245 | + static bool hasMatch({ | ||
| 246 | + required String pushedRoute, | ||
| 247 | + required routeName, | ||
| 248 | + bool withChildren = false, | ||
| 249 | + }) { | ||
| 250 | + final data = RouteParser(pushedRoute: pushedRoute, routeName: routeName); | ||
| 251 | + final matches = <bool>[]; | ||
| 252 | + | ||
| 253 | + final minLength = | ||
| 254 | + min(data.originalPathSegments.length, data.newPathSegments.length); | ||
| 255 | + | ||
| 256 | + if ((!withChildren && | ||
| 257 | + data.newPathSegments.length > data.originalPathSegments.length) || | ||
| 258 | + data.newPathSegments.length < data.originalPathSegments.length) { | ||
| 259 | + matches.add(false); | ||
| 260 | + } | ||
| 261 | + | ||
| 262 | + for (var i = 0; i < minLength; i++) { | ||
| 263 | + final originalPathSegment = data.originalPathSegments[i]; | ||
| 264 | + final newPathSegment = Uri.parse(data.newPathSegments[i]); | ||
| 265 | + | ||
| 266 | + if (originalPathSegment.startsWith(':')) { | ||
| 267 | + matches.add(true); | ||
| 268 | + continue; | ||
| 269 | + } | ||
| 270 | + | ||
| 271 | + if (newPathSegment.path == originalPathSegment) { | ||
| 272 | + matches.add(true); | ||
| 273 | + continue; | ||
| 274 | + } else { | ||
| 275 | + matches.add(false); | ||
| 276 | + break; | ||
| 277 | + } | ||
| 278 | + } | ||
| 279 | + | ||
| 280 | + return matches.every((element) => element); | ||
| 281 | + } | ||
| 282 | + | ||
| 283 | + RouteParser({required String routeName, required String pushedRoute}) | ||
| 284 | + : _cleanRouteName = '/' + | ||
| 285 | + routeName | ||
| 286 | + .replaceAll(RegExp(r'^\s+|\s+$'), '') | ||
| 287 | + .replaceAll(RegExp(r'^\/+|\/+$'), ''), | ||
| 288 | + newRouteUri = Uri.parse(pushedRoute) { | ||
| 289 | + originalRouteUri = Uri(path: _cleanRouteName); | ||
| 290 | + } | ||
| 291 | + late final Uri originalRouteUri; | ||
| 292 | + | ||
| 293 | + final Uri newRouteUri; | ||
| 294 | + final Map<String, String> parameters = <String, String>{}; | ||
| 295 | + final List<Uri> matchingSegments = <Uri>[]; | ||
| 296 | + final String _cleanRouteName; | ||
| 297 | + | ||
| 298 | + List<String> get newPathSegments => newRouteUri.pathSegments; | ||
| 299 | + List<String> get originalPathSegments => originalRouteUri.pathSegments; | ||
| 300 | + String get matchingPath => '/' + matchingSegments.join('/'); | ||
| 301 | + | ||
| 302 | + @override | ||
| 303 | + String toString() => | ||
| 304 | + 'RouteParser(originalRouteUri: $originalRouteUri, newRouteUri: $newRouteUri, _cleanRouteName: $_cleanRouteName)'; | ||
| 305 | +} | 
| @@ -234,8 +234,9 @@ class PageRedirect { | @@ -234,8 +234,9 @@ class PageRedirect { | ||
| 234 | if (settings == null && route != null) { | 234 | if (settings == null && route != null) { | 
| 235 | settings = route; | 235 | settings = route; | 
| 236 | } | 236 | } | 
| 237 | - final match = context.navigation.matchRoute(settings!.name!); | ||
| 238 | - Get.parameters = match.parameters; | 237 | + final match = context.navigation | 
| 238 | + .matchRoute((settings!.arguments as PageSettings).name); | ||
| 239 | + Get.parameters = match!.parameters; | ||
| 239 | 240 | ||
| 240 | // No Match found | 241 | // No Match found | 
| 241 | if (match.route == null) { | 242 | if (match.route == null) { | 
| @@ -147,7 +147,8 @@ class GetRouterOutlet extends RouterOutlet<GetDelegate, RouteDecoder> { | @@ -147,7 +147,8 @@ class GetRouterOutlet extends RouterOutlet<GetDelegate, RouteDecoder> { | ||
| 147 | return ret; | 147 | return ret; | 
| 148 | }, | 148 | }, | 
| 149 | emptyPage: (delegate) => | 149 | emptyPage: (delegate) => | 
| 150 | - delegate.matchRoute(initialRoute).route ?? delegate.notFoundRoute, | 150 | + delegate.matchRoute(initialRoute)?.route ?? | 
| 151 | + delegate.notFoundRoute, | ||
| 151 | key: Get.nestedKey(anchorRoute)?.navigatorKey, | 152 | key: Get.nestedKey(anchorRoute)?.navigatorKey, | 
| 152 | delegate: delegate, | 153 | delegate: delegate, | 
| 153 | ); | 154 | ); | 
| @@ -452,7 +452,8 @@ class BindElement<T> extends InheritedElement { | @@ -452,7 +452,8 @@ class BindElement<T> extends InheritedElement { | ||
| 452 | 452 | ||
| 453 | _controllerBuilder = () => Get.find<T>(tag: widget.tag); | 453 | _controllerBuilder = () => Get.find<T>(tag: widget.tag); | 
| 454 | } else { | 454 | } else { | 
| 455 | - _controllerBuilder = widget.create?.call(this) ?? widget.init; | 455 | + _controllerBuilder = | 
| 456 | + () => (widget.create?.call(this) ?? widget.init?.call()); | ||
| 456 | _isCreator = true; | 457 | _isCreator = true; | 
| 457 | if (widget.lazy) { | 458 | if (widget.lazy) { | 
| 458 | Get.lazyPut<T>(_controllerBuilder!, tag: widget.tag); | 459 | Get.lazyPut<T>(_controllerBuilder!, tag: widget.tag); | 
| 1 | name: get | 1 | name: get | 
| 2 | description: Open screens/snackbars/dialogs without context, manage states and inject dependencies easily with GetX. | 2 | description: Open screens/snackbars/dialogs without context, manage states and inject dependencies easily with GetX. | 
| 3 | -version: 5.0.0-beta.50 | 3 | +version: 5.0.0-beta.51 | 
| 4 | homepage: https://github.com/jonataslaw/getx | 4 | homepage: https://github.com/jonataslaw/getx | 
| 5 | 5 | ||
| 6 | environment: | 6 | environment: | 
test/.DS_Store
deleted
100644 → 0
No preview for this file type
| @@ -4,7 +4,7 @@ import 'package:get/get.dart'; | @@ -4,7 +4,7 @@ import 'package:get/get.dart'; | ||
| 4 | 4 | ||
| 5 | void main() { | 5 | void main() { | 
| 6 | test('Parse Page with children', () { | 6 | test('Parse Page with children', () { | 
| 7 | - final testParams = {'hi': 'value'}; | 7 | + // final testParams = {'hi': 'value'}; | 
| 8 | final pageTree = GetPage( | 8 | final pageTree = GetPage( | 
| 9 | name: '/city', | 9 | name: '/city', | 
| 10 | page: () => Container(), | 10 | page: () => Container(), | 
| @@ -40,7 +40,7 @@ void main() { | @@ -40,7 +40,7 @@ void main() { | ||
| 40 | name: '/pen', | 40 | name: '/pen', | 
| 41 | transition: Transition.cupertino, | 41 | transition: Transition.cupertino, | 
| 42 | page: () => Container(), | 42 | page: () => Container(), | 
| 43 | - parameters: testParams, | 43 | + // parameters: testParams, | 
| 44 | ), | 44 | ), | 
| 45 | GetPage( | 45 | GetPage( | 
| 46 | name: '/paper', | 46 | name: '/paper', | 
| @@ -58,20 +58,63 @@ void main() { | @@ -58,20 +58,63 @@ void main() { | ||
| 58 | ), | 58 | ), | 
| 59 | ], | 59 | ], | 
| 60 | ); | 60 | ); | 
| 61 | + final routes = <GetPage>[]; | ||
| 62 | + final tree = ParseRouteTree(); | ||
| 61 | 63 | ||
| 62 | - final tree = ParseRouteTree(routes: <GetPage>[]); | ||
| 63 | - | ||
| 64 | - tree.addRoute(pageTree); | 64 | + routes.addRoute(pageTree); | 
| 65 | 65 | ||
| 66 | // tree.addRoute(pageTree); | 66 | // tree.addRoute(pageTree); | 
| 67 | final searchRoute = '/city/work/office/pen'; | 67 | final searchRoute = '/city/work/office/pen'; | 
| 68 | - final match = tree.matchRoute(searchRoute); | 68 | + final match = tree.matchRoute(routes, searchRoute); | 
| 69 | expect(match, isNotNull); | 69 | expect(match, isNotNull); | 
| 70 | expect(match.route!.name, searchRoute); | 70 | expect(match.route!.name, searchRoute); | 
| 71 | - final testRouteParam = match.route!.parameters!; | 71 | + final testRouteParam = match.parameters; | 
| 72 | + print(testRouteParam); | ||
| 73 | + // for (final tParam in testParams.entries) { | ||
| 74 | + // expect(testRouteParam[tParam.key], tParam.value); | ||
| 75 | + // } | ||
| 76 | + }); | ||
| 77 | + | ||
| 78 | + test('Parse ', () { | ||
| 79 | + final testParams = {'hi': 'value'}; | ||
| 80 | + final pageTree = GetPage( | ||
| 81 | + name: '/city', | ||
| 82 | + parameters: testParams, | ||
| 83 | + page: () => Container(), | ||
| 84 | + ); | ||
| 85 | + final routes = <GetPage>[]; | ||
| 86 | + final tree = ParseRouteTree(); | ||
| 87 | + | ||
| 88 | + routes.addRoute(pageTree); | ||
| 89 | + | ||
| 90 | + // tree.addRoute(pageTree); | ||
| 91 | + final searchRoute = '/city?abc=1234'; | ||
| 92 | + | ||
| 93 | + final hasMatch = RouteParser.hasMatch( | ||
| 94 | + pushedRoute: searchRoute, routeName: pageTree.name); | ||
| 95 | + expect(hasMatch, true); | ||
| 96 | + | ||
| 97 | + final parsed = | ||
| 98 | + RouteParser.parse(pushedRoute: searchRoute, routeName: pageTree.name); | ||
| 99 | + | ||
| 100 | + final match = tree.matchRoute(routes, searchRoute); | ||
| 101 | + expect(match, isNotNull); | ||
| 102 | + expect(parsed.newRouteUri.toString(), searchRoute); | ||
| 103 | + final testRouteParam = match.route?.parameters; | ||
| 104 | + | ||
| 72 | for (final tParam in testParams.entries) { | 105 | for (final tParam in testParams.entries) { | 
| 73 | - expect(testRouteParam[tParam.key], tParam.value); | 106 | + expect(testRouteParam![tParam.key], tParam.value); | 
| 74 | } | 107 | } | 
| 108 | + | ||
| 109 | + final hasMatch2 = RouteParser.hasMatch( | ||
| 110 | + pushedRoute: '/home/123/ana', routeName: '/home/:id/:name'); | ||
| 111 | + print(hasMatch2); | ||
| 112 | + expect(hasMatch2, true); | ||
| 113 | + | ||
| 114 | + final parsed2 = RouteParser.parse( | ||
| 115 | + pushedRoute: '/home/123/ana/profile', | ||
| 116 | + routeName: '/home/:id/:name/profile'); | ||
| 117 | + print(parsed2.parameters); | ||
| 75 | }); | 118 | }); | 
| 76 | 119 | ||
| 77 | test('Parse Page without children', () { | 120 | test('Parse Page without children', () { | 
| @@ -114,14 +157,14 @@ void main() { | @@ -114,14 +157,14 @@ void main() { | ||
| 114 | transition: Transition.rightToLeft), | 157 | transition: Transition.rightToLeft), | 
| 115 | ]; | 158 | ]; | 
| 116 | 159 | ||
| 117 | - final tree = ParseRouteTree(routes: pageTree); | 160 | + final tree = ParseRouteTree(); | 
| 118 | 161 | ||
| 119 | // for (var p in pageTree) { | 162 | // for (var p in pageTree) { | 
| 120 | // tree.addRoute(p); | 163 | // tree.addRoute(p); | 
| 121 | // } | 164 | // } | 
| 122 | 165 | ||
| 123 | final searchRoute = '/city/work/office/pen'; | 166 | final searchRoute = '/city/work/office/pen'; | 
| 124 | - final match = tree.matchRoute(searchRoute); | 167 | + final match = tree.matchRoute(pageTree, searchRoute); | 
| 125 | expect(match, isNotNull); | 168 | expect(match, isNotNull); | 
| 126 | expect(match.route!.name, searchRoute); | 169 | expect(match.route!.name, searchRoute); | 
| 127 | }); | 170 | }); | 
| @@ -139,6 +182,8 @@ void main() { | @@ -139,6 +182,8 @@ void main() { | ||
| 139 | ], | 182 | ], | 
| 140 | )); | 183 | )); | 
| 141 | 184 | ||
| 185 | + print(Get.parameters); | ||
| 186 | + | ||
| 142 | expect(Get.parameters['name'], 'juan'); | 187 | expect(Get.parameters['name'], 'juan'); | 
| 143 | 188 | ||
| 144 | Get.toNamed('/second/1234'); | 189 | Get.toNamed('/second/1234'); | 
| @@ -59,25 +59,25 @@ void main() { | @@ -59,25 +59,25 @@ void main() { | ||
| 59 | test('interval', () async { | 59 | test('interval', () async { | 
| 60 | final count = 0.obs; | 60 | final count = 0.obs; | 
| 61 | int? result = -1; | 61 | int? result = -1; | 
| 62 | - interval(count, (dynamic _) { | ||
| 63 | - // print(_); | ||
| 64 | - result = _ as int?; | 62 | + interval<int>(count, (v) { | 
| 63 | + print(v); | ||
| 64 | + result = v; | ||
| 65 | }, time: Duration(milliseconds: 100)); | 65 | }, time: Duration(milliseconds: 100)); | 
| 66 | 66 | ||
| 67 | count.value++; | 67 | count.value++; | 
| 68 | await Future.delayed(Duration.zero); | 68 | await Future.delayed(Duration.zero); | 
| 69 | await Future.delayed(Duration(milliseconds: 100)); | 69 | await Future.delayed(Duration(milliseconds: 100)); | 
| 70 | - expect(1, result); | 70 | + expect(result, 1); | 
| 71 | count.value++; | 71 | count.value++; | 
| 72 | count.value++; | 72 | count.value++; | 
| 73 | count.value++; | 73 | count.value++; | 
| 74 | await Future.delayed(Duration.zero); | 74 | await Future.delayed(Duration.zero); | 
| 75 | await Future.delayed(Duration(milliseconds: 100)); | 75 | await Future.delayed(Duration(milliseconds: 100)); | 
| 76 | - expect(2, result); | 76 | + expect(result, 2); | 
| 77 | count.value++; | 77 | count.value++; | 
| 78 | await Future.delayed(Duration.zero); | 78 | await Future.delayed(Duration.zero); | 
| 79 | await Future.delayed(Duration(milliseconds: 100)); | 79 | await Future.delayed(Duration(milliseconds: 100)); | 
| 80 | - expect(5, result); | 80 | + expect(result, 5); | 
| 81 | }); | 81 | }); | 
| 82 | 82 | ||
| 83 | test('bindStream test', () async { | 83 | test('bindStream test', () async { | 
| @@ -128,6 +128,7 @@ void main() { | @@ -128,6 +128,7 @@ void main() { | ||
| 128 | reactiveInteger.trigger(3); | 128 | reactiveInteger.trigger(3); | 
| 129 | 129 | ||
| 130 | await Future.delayed(Duration(milliseconds: 100)); | 130 | await Future.delayed(Duration(milliseconds: 100)); | 
| 131 | + print(timesCalled); | ||
| 131 | expect(3, timesCalled); | 132 | expect(3, timesCalled); | 
| 132 | }); | 133 | }); | 
| 133 | 134 | 
- 
Please register or login to post a comment