Showing
10 changed files
with
43 additions
and
25 deletions
| @@ -16,6 +16,15 @@ class HomeController extends SuperController<CasesModel> { | @@ -16,6 +16,15 @@ class HomeController extends SuperController<CasesModel> { | ||
| 16 | append(() => homeRepository.getCases); | 16 | append(() => homeRepository.getCases); |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | + Country getCountryById(String id) { | ||
| 20 | + final index = int.tryParse(id); | ||
| 21 | + if (index != null) { | ||
| 22 | + return state!.countries[index]; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + return state!.countries.first; | ||
| 26 | + } | ||
| 27 | + | ||
| 19 | @override | 28 | @override |
| 20 | void onReady() { | 29 | void onReady() { |
| 21 | print('The build method is done. ' | 30 | print('The build method is done. ' |
| @@ -34,8 +34,8 @@ class CountryView extends GetView<HomeController> { | @@ -34,8 +34,8 @@ class CountryView extends GetView<HomeController> { | ||
| 34 | return ListTile( | 34 | return ListTile( |
| 35 | onTap: () { | 35 | onTap: () { |
| 36 | //Get.rootDelegate.toNamed('/home/country'); | 36 | //Get.rootDelegate.toNamed('/home/country'); |
| 37 | - Get.rootDelegate.toNamed('/home/country/details', | ||
| 38 | - arguments: country); | 37 | + Get.rootDelegate |
| 38 | + .offNamed('/home/country/details?id=$index'); | ||
| 39 | }, | 39 | }, |
| 40 | trailing: CircleAvatar( | 40 | trailing: CircleAvatar( |
| 41 | backgroundImage: NetworkImage( | 41 | backgroundImage: NetworkImage( |
| @@ -2,13 +2,13 @@ import 'dart:ui'; | @@ -2,13 +2,13 @@ import 'dart:ui'; | ||
| 2 | 2 | ||
| 3 | import 'package:flutter/material.dart'; | 3 | import 'package:flutter/material.dart'; |
| 4 | import 'package:get/get.dart'; | 4 | import 'package:get/get.dart'; |
| 5 | +import '../controllers/home_controller.dart'; | ||
| 5 | 6 | ||
| 6 | -import '../../domain/entity/cases_model.dart'; | ||
| 7 | - | ||
| 8 | -class DetailsView extends StatelessWidget { | 7 | +class DetailsView extends GetView<HomeController> { |
| 9 | @override | 8 | @override |
| 10 | Widget build(BuildContext context) { | 9 | Widget build(BuildContext context) { |
| 11 | - final country = Get.rootDelegate.arguments<Country>(); | 10 | + final parameter = Get.rootDelegate.parameters; |
| 11 | + final country = controller.getCountryById(parameter['id'] ?? ''); | ||
| 12 | return Container( | 12 | return Container( |
| 13 | decoration: BoxDecoration( | 13 | decoration: BoxDecoration( |
| 14 | image: DecorationImage( | 14 | image: DecorationImage( |
| @@ -32,7 +32,7 @@ class LoginView extends GetView<LoginController> { | @@ -32,7 +32,7 @@ class LoginView extends GetView<LoginController> { | ||
| 32 | onPressed: () { | 32 | onPressed: () { |
| 33 | AuthService.to.login(); | 33 | AuthService.to.login(); |
| 34 | final thenTo = Get.rootDelegate.currentConfiguration! | 34 | final thenTo = Get.rootDelegate.currentConfiguration! |
| 35 | - .currentPage!.parameter?['then']; | 35 | + .currentPage!.parameters?['then']; |
| 36 | Get.rootDelegate.offNamed(thenTo ?? Routes.HOME); | 36 | Get.rootDelegate.offNamed(thenTo ?? Routes.HOME); |
| 37 | }, | 37 | }, |
| 38 | ), | 38 | ), |
| @@ -112,6 +112,10 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | @@ -112,6 +112,10 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | ||
| 112 | return currentConfiguration?.currentPage?.arguments as T; | 112 | return currentConfiguration?.currentPage?.arguments as T; |
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | + Map<String, String> get parameters { | ||
| 116 | + return currentConfiguration?.currentPage?.parameters ?? {}; | ||
| 117 | + } | ||
| 118 | + | ||
| 115 | // void _unsafeHistoryClear() { | 119 | // void _unsafeHistoryClear() { |
| 116 | // history.clear(); | 120 | // history.clear(); |
| 117 | // } | 121 | // } |
| @@ -144,7 +148,7 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | @@ -144,7 +148,7 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | ||
| 144 | if (originalEntryIndex >= 0) { | 148 | if (originalEntryIndex >= 0) { |
| 145 | switch (preventDuplicateHandlingMode) { | 149 | switch (preventDuplicateHandlingMode) { |
| 146 | case PreventDuplicateHandlingMode.PopUntilOriginalRoute: | 150 | case PreventDuplicateHandlingMode.PopUntilOriginalRoute: |
| 147 | - until(config.location!, popMode: PopMode.Page); | 151 | + backUntil(config.location!, popMode: PopMode.Page); |
| 148 | break; | 152 | break; |
| 149 | case PreventDuplicateHandlingMode.ReorderRoutes: | 153 | case PreventDuplicateHandlingMode.ReorderRoutes: |
| 150 | _unsafeHistoryRemoveAt(originalEntryIndex); | 154 | _unsafeHistoryRemoveAt(originalEntryIndex); |
| @@ -231,7 +235,7 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | @@ -231,7 +235,7 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | ||
| 231 | } | 235 | } |
| 232 | 236 | ||
| 233 | bool _canPopHistory() { | 237 | bool _canPopHistory() { |
| 234 | - return history.length > 1; | 238 | + return history.length > 0; |
| 235 | } | 239 | } |
| 236 | 240 | ||
| 237 | Future<bool> canPopHistory() { | 241 | Future<bool> canPopHistory() { |
| @@ -324,7 +328,6 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | @@ -324,7 +328,6 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | ||
| 324 | } | 328 | } |
| 325 | 329 | ||
| 326 | final decoder = Get.routeTree.matchRoute(page, arguments: arguments); | 330 | final decoder = Get.routeTree.matchRoute(page, arguments: arguments); |
| 327 | - Get.parameters = decoder.parameters; | ||
| 328 | decoder.replaceArguments(arguments); | 331 | decoder.replaceArguments(arguments); |
| 329 | 332 | ||
| 330 | return pushHistory<T>( | 333 | return pushHistory<T>( |
| @@ -345,7 +348,7 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | @@ -345,7 +348,7 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | ||
| 345 | /// Removes routes according to [PopMode] | 348 | /// Removes routes according to [PopMode] |
| 346 | /// until it reaches the specifc [fullRoute], | 349 | /// until it reaches the specifc [fullRoute], |
| 347 | /// DOES NOT remove the [fullRoute] | 350 | /// DOES NOT remove the [fullRoute] |
| 348 | - void until( | 351 | + void backUntil( |
| 349 | String fullRoute, { | 352 | String fullRoute, { |
| 350 | PopMode popMode = PopMode.Page, | 353 | PopMode popMode = PopMode.Page, |
| 351 | }) { | 354 | }) { |
| @@ -18,6 +18,14 @@ class RouteDecoder { | @@ -18,6 +18,14 @@ class RouteDecoder { | ||
| 18 | treeBranch[index] = _route.copy(arguments: arguments); | 18 | treeBranch[index] = _route.copy(arguments: arguments); |
| 19 | } | 19 | } |
| 20 | } | 20 | } |
| 21 | + | ||
| 22 | + void replaceParameters(Object? arguments) { | ||
| 23 | + final _route = route; | ||
| 24 | + if (_route != null) { | ||
| 25 | + final index = treeBranch.indexOf(_route); | ||
| 26 | + treeBranch[index] = _route.copy(parameters: parameters); | ||
| 27 | + } | ||
| 28 | + } | ||
| 21 | } | 29 | } |
| 22 | 30 | ||
| 23 | class ParseRouteTree { | 31 | class ParseRouteTree { |
| @@ -62,8 +70,8 @@ class ParseRouteTree { | @@ -62,8 +70,8 @@ class ParseRouteTree { | ||
| 62 | final mappedTreeBranch = treeBranch | 70 | final mappedTreeBranch = treeBranch |
| 63 | .map( | 71 | .map( |
| 64 | (e) => e.value.copy( | 72 | (e) => e.value.copy( |
| 65 | - parameter: { | ||
| 66 | - if (e.value.parameter != null) ...e.value.parameter!, | 73 | + parameters: { |
| 74 | + if (e.value.parameters != null) ...e.value.parameters!, | ||
| 67 | ...params, | 75 | ...params, |
| 68 | }, | 76 | }, |
| 69 | name: e.key, | 77 | name: e.key, |
| @@ -30,7 +30,7 @@ class PathDecoded { | @@ -30,7 +30,7 @@ class PathDecoded { | ||
| 30 | class GetPage<T> extends Page<T> { | 30 | class GetPage<T> extends Page<T> { |
| 31 | final GetPageBuilder page; | 31 | final GetPageBuilder page; |
| 32 | final bool? popGesture; | 32 | final bool? popGesture; |
| 33 | - final Map<String, String>? parameter; | 33 | + final Map<String, String>? parameters; |
| 34 | final String? title; | 34 | final String? title; |
| 35 | final Transition? transition; | 35 | final Transition? transition; |
| 36 | final Curve curve; | 36 | final Curve curve; |
| @@ -72,7 +72,7 @@ class GetPage<T> extends Page<T> { | @@ -72,7 +72,7 @@ class GetPage<T> extends Page<T> { | ||
| 72 | this.maintainState = true, | 72 | this.maintainState = true, |
| 73 | this.curve = Curves.linear, | 73 | this.curve = Curves.linear, |
| 74 | this.alignment, | 74 | this.alignment, |
| 75 | - this.parameter, | 75 | + this.parameters, |
| 76 | this.opaque = true, | 76 | this.opaque = true, |
| 77 | this.transitionDuration, | 77 | this.transitionDuration, |
| 78 | this.popGesture, | 78 | this.popGesture, |
| @@ -119,7 +119,7 @@ class GetPage<T> extends Page<T> { | @@ -119,7 +119,7 @@ class GetPage<T> extends Page<T> { | ||
| 119 | String? name, | 119 | String? name, |
| 120 | GetPageBuilder? page, | 120 | GetPageBuilder? page, |
| 121 | bool? popGesture, | 121 | bool? popGesture, |
| 122 | - Map<String, String>? parameter, | 122 | + Map<String, String>? parameters, |
| 123 | String? title, | 123 | String? title, |
| 124 | Transition? transition, | 124 | Transition? transition, |
| 125 | Curve? curve, | 125 | Curve? curve, |
| @@ -147,7 +147,7 @@ class GetPage<T> extends Page<T> { | @@ -147,7 +147,7 @@ class GetPage<T> extends Page<T> { | ||
| 147 | name: name ?? this.name, | 147 | name: name ?? this.name, |
| 148 | page: page ?? this.page, | 148 | page: page ?? this.page, |
| 149 | popGesture: popGesture ?? this.popGesture, | 149 | popGesture: popGesture ?? this.popGesture, |
| 150 | - parameter: parameter ?? this.parameter, | 150 | + parameters: parameters ?? this.parameters, |
| 151 | title: title ?? this.title, | 151 | title: title ?? this.title, |
| 152 | transition: transition ?? this.transition, | 152 | transition: transition ?? this.transition, |
| 153 | curve: curve ?? this.curve, | 153 | curve: curve ?? this.curve, |
| @@ -196,7 +196,6 @@ class GetObserver extends NavigatorObserver { | @@ -196,7 +196,6 @@ class GetObserver extends NavigatorObserver { | ||
| 196 | value.isDialog = currentRoute.isDialog ? false : value.isDialog; | 196 | value.isDialog = currentRoute.isDialog ? false : value.isDialog; |
| 197 | }); | 197 | }); |
| 198 | if (oldRoute is GetPageRoute) { | 198 | if (oldRoute is GetPageRoute) { |
| 199 | - print(oldRoute.reference); | ||
| 200 | GetInstance().reloadDependencyByRoute(oldRoute.reference); | 199 | GetInstance().reloadDependencyByRoute(oldRoute.reference); |
| 201 | } | 200 | } |
| 202 | 201 | ||
| @@ -223,7 +222,6 @@ class GetObserver extends NavigatorObserver { | @@ -223,7 +222,6 @@ class GetObserver extends NavigatorObserver { | ||
| 223 | }); | 222 | }); |
| 224 | 223 | ||
| 225 | if (route is GetPageRoute) { | 224 | if (route is GetPageRoute) { |
| 226 | - print(route.reference); | ||
| 227 | GetInstance().reloadDependencyByRoute(route.reference); | 225 | GetInstance().reloadDependencyByRoute(route.reference); |
| 228 | } | 226 | } |
| 229 | routing?.call(_routeSend); | 227 | routing?.call(_routeSend); |
| @@ -196,7 +196,7 @@ class PageRedirect { | @@ -196,7 +196,7 @@ class PageRedirect { | ||
| 196 | final _r = (isUnknown ? unknownRoute : route)!; | 196 | final _r = (isUnknown ? unknownRoute : route)!; |
| 197 | return GetPageRoute<T>( | 197 | return GetPageRoute<T>( |
| 198 | page: _r.page, | 198 | page: _r.page, |
| 199 | - parameter: _r.parameter, | 199 | + parameter: _r.parameters, |
| 200 | settings: isUnknown | 200 | settings: isUnknown |
| 201 | ? RouteSettings( | 201 | ? RouteSettings( |
| 202 | name: _r.name, | 202 | name: _r.name, |
| @@ -225,7 +225,7 @@ class PageRedirect { | @@ -225,7 +225,7 @@ class PageRedirect { | ||
| 225 | 225 | ||
| 226 | return GetPageRoute<T>( | 226 | return GetPageRoute<T>( |
| 227 | page: _r.page, | 227 | page: _r.page, |
| 228 | - parameter: _r.parameter, | 228 | + parameter: _r.parameters, |
| 229 | alignment: _r.alignment, | 229 | alignment: _r.alignment, |
| 230 | title: _r.title, | 230 | title: _r.title, |
| 231 | maintainState: _r.maintainState, | 231 | maintainState: _r.maintainState, |
| @@ -277,10 +277,10 @@ class PageRedirect { | @@ -277,10 +277,10 @@ class PageRedirect { | ||
| 277 | } | 277 | } |
| 278 | 278 | ||
| 279 | void addPageParameter(GetPage route) { | 279 | void addPageParameter(GetPage route) { |
| 280 | - if (route.parameter == null) return; | 280 | + if (route.parameters == null) return; |
| 281 | 281 | ||
| 282 | final parameters = Get.parameters; | 282 | final parameters = Get.parameters; |
| 283 | - parameters.addEntries(route.parameter!.entries); | 283 | + parameters.addEntries(route.parameters!.entries); |
| 284 | Get.parameters = parameters; | 284 | Get.parameters = parameters; |
| 285 | } | 285 | } |
| 286 | } | 286 | } |
| @@ -25,7 +25,7 @@ void main() { | @@ -25,7 +25,7 @@ void main() { | ||
| 25 | GetPage( | 25 | GetPage( |
| 26 | name: '/pen', | 26 | name: '/pen', |
| 27 | page: () => Container(), | 27 | page: () => Container(), |
| 28 | - parameter: testParams, | 28 | + parameters: testParams, |
| 29 | ), | 29 | ), |
| 30 | GetPage(name: '/paper', page: () => Container()), | 30 | GetPage(name: '/paper', page: () => Container()), |
| 31 | ], | 31 | ], |
| @@ -48,7 +48,7 @@ void main() { | @@ -48,7 +48,7 @@ void main() { | ||
| 48 | final match = tree.matchRoute(searchRoute); | 48 | final match = tree.matchRoute(searchRoute); |
| 49 | expect(match, isNotNull); | 49 | expect(match, isNotNull); |
| 50 | expect(match.route!.name, searchRoute); | 50 | expect(match.route!.name, searchRoute); |
| 51 | - final testRouteParam = match.route!.parameter!; | 51 | + final testRouteParam = match.route!.parameters!; |
| 52 | for (final tParam in testParams.entries) { | 52 | for (final tParam in testParams.entries) { |
| 53 | expect(testRouteParam[tParam.key], tParam.value); | 53 | expect(testRouteParam[tParam.key], tParam.value); |
| 54 | } | 54 | } |
-
Please register or login to post a comment