Committed by
GitHub
Merge pull request #861 from vbuberen/update/nav_extensions_docs
Update offUntil and offNamedUntil docs
Showing
2 changed files
with
31 additions
and
16 deletions
| @@ -2,6 +2,7 @@ import 'dart:ui' as ui; | @@ -2,6 +2,7 @@ import 'dart:ui' as ui; | ||
| 2 | 2 | ||
| 3 | import 'package:flutter/material.dart'; | 3 | import 'package:flutter/material.dart'; |
| 4 | import 'package:flutter/scheduler.dart'; | 4 | import 'package:flutter/scheduler.dart'; |
| 5 | + | ||
| 5 | import '../../get_core/get_core.dart'; | 6 | import '../../get_core/get_core.dart'; |
| 6 | import '../../get_instance/src/bindings_interface.dart'; | 7 | import '../../get_instance/src/bindings_interface.dart'; |
| 7 | import '../../get_utils/get_utils.dart'; | 8 | import '../../get_utils/get_utils.dart'; |
| @@ -592,11 +593,11 @@ extension GetNavigation on GetInterface { | @@ -592,11 +593,11 @@ extension GetNavigation on GetInterface { | ||
| 592 | /// | 593 | /// |
| 593 | /// Obs: unlike other get methods, this one you need to send a function | 594 | /// Obs: unlike other get methods, this one you need to send a function |
| 594 | /// that returns the widget to the page argument, like this: | 595 | /// that returns the widget to the page argument, like this: |
| 595 | - /// Get.offUntil( () => HomePage() ) | 596 | + /// Get.offUntil(GetPageRoute(page: () => HomePage()), predicate) |
| 596 | /// | 597 | /// |
| 597 | /// [predicate] can be used like this: | 598 | /// [predicate] can be used like this: |
| 598 | - /// `Get.until((route) => Get.currentRoute == '/home')`so when you get to home page, | ||
| 599 | - /// | 599 | + /// `Get.offUntil(page, (route) => (route as GetPageRoute).routeName == '/home')` |
| 600 | + /// to pop routes in stack until home, | ||
| 600 | /// or also like this: | 601 | /// or also like this: |
| 601 | /// `Get.until((route) => !Get.isDialogOpen())`, to make sure the dialog | 602 | /// `Get.until((route) => !Get.isDialogOpen())`, to make sure the dialog |
| 602 | /// is closed | 603 | /// is closed |
| @@ -617,12 +618,13 @@ extension GetNavigation on GetInterface { | @@ -617,12 +618,13 @@ extension GetNavigation on GetInterface { | ||
| 617 | /// as explained in documentation | 618 | /// as explained in documentation |
| 618 | /// | 619 | /// |
| 619 | /// [predicate] can be used like this: | 620 | /// [predicate] can be used like this: |
| 620 | - /// `Get.until((route) => Get.currentRoute == '/home')`so when you get to home page, | ||
| 621 | - /// or also like | ||
| 622 | - /// `Get.until((route) => !Get.isDialogOpen())`, to make sure the dialog | ||
| 623 | - /// is closed | 621 | + /// `Get.offNamedUntil(page, ModalRoute.withName('/home'))` |
| 622 | + /// to pop routes in stack until home, | ||
| 623 | + /// or like this: | ||
| 624 | + /// `Get.offNamedUntil((route) => !Get.isDialogOpen())`, | ||
| 625 | + /// to make sure the dialog is closed | ||
| 624 | /// | 626 | /// |
| 625 | - /// Note: Always put a slash on the route ('/page1'), to avoid unnexpected errors | 627 | + /// Note: Always put a slash on the route name ('/page1'), to avoid unexpected errors |
| 626 | Future<T> offNamedUntil<T>( | 628 | Future<T> offNamedUntil<T>( |
| 627 | String page, | 629 | String page, |
| 628 | RoutePredicate predicate, { | 630 | RoutePredicate predicate, { |
| 1 | import 'package:flutter/material.dart'; | 1 | import 'package:flutter/material.dart'; |
| 2 | import 'package:flutter_test/flutter_test.dart'; | 2 | import 'package:flutter_test/flutter_test.dart'; |
| 3 | import 'package:get/get.dart'; | 3 | import 'package:get/get.dart'; |
| 4 | + | ||
| 4 | import 'utils/wrapper.dart'; | 5 | import 'utils/wrapper.dart'; |
| 5 | 6 | ||
| 6 | class SizeTransitions extends CustomTransition { | 7 | class SizeTransitions extends CustomTransition { |
| @@ -198,16 +199,21 @@ void main() { | @@ -198,16 +199,21 @@ void main() { | ||
| 198 | 199 | ||
| 199 | await tester.pumpAndSettle(); | 200 | await tester.pumpAndSettle(); |
| 200 | 201 | ||
| 201 | - expect(find.byType(FirstScreen), findsOneWidget); | 202 | + Get.to(SecondScreen()); |
| 202 | 203 | ||
| 203 | - Get.offUntil( | ||
| 204 | - MaterialPageRoute(builder: (context) => SecondScreen()), | ||
| 205 | - ModalRoute.withName('/'), | ||
| 206 | - ); | 204 | + await tester.pumpAndSettle(); |
| 205 | + | ||
| 206 | + Get.offUntil(GetPageRoute(page: () => ThirdScreen()), | ||
| 207 | + (route) => (route as GetPageRoute).routeName == '/FirstScreen'); | ||
| 207 | 208 | ||
| 208 | await tester.pumpAndSettle(); | 209 | await tester.pumpAndSettle(); |
| 209 | 210 | ||
| 210 | - expect(find.byType(SecondScreen), findsOneWidget); | 211 | + expect(find.byType(ThirdScreen), findsOneWidget); |
| 212 | + Get.back(); | ||
| 213 | + | ||
| 214 | + await tester.pumpAndSettle(); | ||
| 215 | + | ||
| 216 | + expect(find.byType(FirstScreen), findsOneWidget); | ||
| 211 | }); | 217 | }); |
| 212 | 218 | ||
| 213 | testWidgets("Get.offNamedUntil smoke test", (tester) async { | 219 | testWidgets("Get.offNamedUntil smoke test", (tester) async { |
| @@ -232,12 +238,19 @@ void main() { | @@ -232,12 +238,19 @@ void main() { | ||
| 232 | ); | 238 | ); |
| 233 | 239 | ||
| 234 | Get.toNamed('/first'); | 240 | Get.toNamed('/first'); |
| 241 | + Get.toNamed('/second'); | ||
| 235 | 242 | ||
| 236 | await tester.pumpAndSettle(); | 243 | await tester.pumpAndSettle(); |
| 237 | 244 | ||
| 238 | - expect(find.byType(FirstScreen), findsOneWidget); | 245 | + expect(find.byType(SecondScreen), findsOneWidget); |
| 246 | + | ||
| 247 | + Get.offNamedUntil('/third', ModalRoute.withName('/first')); | ||
| 239 | 248 | ||
| 240 | - Get.offNamedUntil('/first', ModalRoute.withName('/')); | 249 | + await tester.pumpAndSettle(); |
| 250 | + | ||
| 251 | + expect(find.byType(ThirdScreen), findsOneWidget); | ||
| 252 | + | ||
| 253 | + Get.back(); | ||
| 241 | 254 | ||
| 242 | await tester.pumpAndSettle(); | 255 | await tester.pumpAndSettle(); |
| 243 | 256 |
-
Please register or login to post a comment