Committed by
GitHub
Merge pull request #1067 from enghitalo/patch-1
params in url by Get.parameters
Showing
2 changed files
with
48 additions
and
0 deletions
| @@ -541,8 +541,20 @@ extension GetNavigation on GetInterface { | @@ -541,8 +541,20 @@ extension GetNavigation on GetInterface { | ||
| 541 | String page, { | 541 | String page, { | 
| 542 | dynamic arguments, | 542 | dynamic arguments, | 
| 543 | int id, | 543 | int id, | 
| 544 | + Map<String, String> parameters, | ||
| 544 | bool preventDuplicates = true, | 545 | bool preventDuplicates = true, | 
| 545 | }) { | 546 | }) { | 
| 547 | + Get.parameters = ({}); | ||
| 548 | + if (parameters != null) { | ||
| 549 | + for (var item in parameters.keys) { | ||
| 550 | + if (page.contains('?')) { | ||
| 551 | + page += "&$item=${parameters[item]}"; | ||
| 552 | + } else { | ||
| 553 | + page += "?$item=${parameters[item]}"; | ||
| 554 | + } | ||
| 555 | + } | ||
| 556 | + } | ||
| 557 | + | ||
| 546 | if (preventDuplicates && page == currentRoute) { | 558 | if (preventDuplicates && page == currentRoute) { | 
| 547 | return null; | 559 | return null; | 
| 548 | } | 560 | } | 
| @@ -87,4 +87,40 @@ void main() { | @@ -87,4 +87,40 @@ void main() { | ||
| 87 | expect(Get.parameters['name'], 'ana'); | 87 | expect(Get.parameters['name'], 'ana'); | 
| 88 | }, | 88 | }, | 
| 89 | ); | 89 | ); | 
| 90 | + | ||
| 91 | + testWidgets( | ||
| 92 | + 'params in url by parameters', | ||
| 93 | + (tester) async { | ||
| 94 | + print("Iniciando test"); | ||
| 95 | + await tester.pumpWidget(GetMaterialApp( | ||
| 96 | + initialRoute: '/first/juan', | ||
| 97 | + getPages: [ | ||
| 98 | + GetPage(page: () => Container(), name: '/buda'), | ||
| 99 | + GetPage(page: () => Container(), name: '/italy'), | ||
| 100 | + ], | ||
| 101 | + )); | ||
| 102 | + | ||
| 103 | + // Get.parameters = ({"varginias": "varginia", "vinis": "viniiss"}); | ||
| 104 | + var parameters = <String, String>{ | ||
| 105 | + "varginias": "varginia", | ||
| 106 | + "vinis": "viniiss" | ||
| 107 | + }; | ||
| 108 | + // print("Get.parameters: ${Get.parameters}"); | ||
| 109 | + parameters.addAll({"a": "b", "c": "d"}); | ||
| 110 | + Get.toNamed("/buda", parameters: parameters); | ||
| 111 | + | ||
| 112 | + await tester.pumpAndSettle(); | ||
| 113 | + expect(Get.parameters['varginias'], 'varginia'); | ||
| 114 | + expect(Get.parameters['vinis'], 'viniiss'); | ||
| 115 | + expect(Get.parameters['a'], 'b'); | ||
| 116 | + expect(Get.parameters['c'], 'd'); | ||
| 117 | + | ||
| 118 | + Map<String, String> italyParameters; | ||
| 119 | + italyParameters = {"ja": "ca", "que": "i"}; | ||
| 120 | + Get.toNamed("/italy", parameters: italyParameters); | ||
| 121 | + await tester.pumpAndSettle(); | ||
| 122 | + expect(Get.parameters['ja'], 'ca'); | ||
| 123 | + expect(Get.parameters['que'], 'i'); | ||
| 124 | + }, | ||
| 125 | + ); | ||
| 90 | } | 126 | } | 
- 
Please register or login to post a comment