Fixes transitions and curves arguments in navigation methods
- renamed and added defaults transition duration and types in "GetInterfase" - added missing parameters in `Get.to` / `Get.offAll`, fixes #570 - added optional `transitionDuration` and `transitionCurve` to `Get.dialog()`
Showing
3 changed files
with
33 additions
and
13 deletions
1 | import 'package:flutter/material.dart'; | 1 | import 'package:flutter/material.dart'; |
2 | + | ||
3 | +import '../../utils.dart'; | ||
2 | import '../navigation/root/parse_route.dart'; | 4 | import '../navigation/root/parse_route.dart'; |
3 | import '../navigation/root/root_controller.dart'; | 5 | import '../navigation/root/root_controller.dart'; |
4 | import '../navigation/routes/custom_transition.dart'; | 6 | import '../navigation/routes/custom_transition.dart'; |
5 | import '../navigation/routes/observers/route_observer.dart'; | 7 | import '../navigation/routes/observers/route_observer.dart'; |
6 | import '../navigation/routes/transitions_type.dart'; | 8 | import '../navigation/routes/transitions_type.dart'; |
7 | -import '../../utils.dart'; | ||
8 | 9 | ||
9 | ///Use Get.to instead of Navigator.push, Get.off instead of Navigator.pushReplacement, | 10 | ///Use Get.to instead of Navigator.push, Get.off instead of Navigator.pushReplacement, |
10 | ///Get.offAll instead of Navigator.pushAndRemoveUntil. For named routes just add "named" | 11 | ///Get.offAll instead of Navigator.pushAndRemoveUntil. For named routes just add "named" |
@@ -16,8 +17,14 @@ import '../../utils.dart'; | @@ -16,8 +17,14 @@ import '../../utils.dart'; | ||
16 | abstract class GetInterface { | 17 | abstract class GetInterface { |
17 | bool defaultPopGesture = GetPlatform.isIOS; | 18 | bool defaultPopGesture = GetPlatform.isIOS; |
18 | bool defaultOpaqueRoute = true; | 19 | bool defaultOpaqueRoute = true; |
20 | + | ||
19 | Transition defaultTransition; | 21 | Transition defaultTransition; |
20 | - Duration defaultDurationTransition = Duration(milliseconds: 400); | 22 | + Duration defaultTransitionDuration = Duration(milliseconds: 400); |
23 | + Curve defaultTransitionCurve = Curves.easeOutQuad; | ||
24 | + | ||
25 | + Curve defaultDialogTransitionCurve = Curves.easeOutQuad; | ||
26 | + Duration defaultDialogTransitionDuration = Duration(milliseconds: 400); | ||
27 | + | ||
21 | bool defaultGlobalState = true; | 28 | bool defaultGlobalState = true; |
22 | RouteSettings settings; | 29 | RouteSettings settings; |
23 | String defaultSeparator = "_"; | 30 | String defaultSeparator = "_"; |
@@ -42,6 +42,7 @@ extension GetNavigation on GetInterface { | @@ -42,6 +42,7 @@ extension GetNavigation on GetInterface { | ||
42 | Widget page, { | 42 | Widget page, { |
43 | bool opaque, | 43 | bool opaque, |
44 | Transition transition, | 44 | Transition transition, |
45 | + Curve curve, | ||
45 | Duration duration, | 46 | Duration duration, |
46 | int id, | 47 | int id, |
47 | bool fullscreenDialog = false, | 48 | bool fullscreenDialog = false, |
@@ -65,9 +66,10 @@ extension GetNavigation on GetInterface { | @@ -65,9 +66,10 @@ extension GetNavigation on GetInterface { | ||
65 | ), | 66 | ), |
66 | popGesture: popGesture ?? defaultPopGesture, | 67 | popGesture: popGesture ?? defaultPopGesture, |
67 | transition: transition ?? defaultTransition, | 68 | transition: transition ?? defaultTransition, |
69 | + curve: curve ?? defaultTransitionCurve, | ||
68 | fullscreenDialog: fullscreenDialog, | 70 | fullscreenDialog: fullscreenDialog, |
69 | binding: binding, | 71 | binding: binding, |
70 | - transitionDuration: duration ?? defaultDurationTransition, | 72 | + transitionDuration: duration ?? defaultTransitionDuration, |
71 | ), | 73 | ), |
72 | ); | 74 | ); |
73 | } | 75 | } |
@@ -317,7 +319,8 @@ extension GetNavigation on GetInterface { | @@ -317,7 +319,8 @@ extension GetNavigation on GetInterface { | ||
317 | /// It has the advantage of not needing context, | 319 | /// It has the advantage of not needing context, |
318 | /// so you can call from your business logic | 320 | /// so you can call from your business logic |
319 | /// | 321 | /// |
320 | - /// You can set a custom [transition], and a transition [duration]. | 322 | + /// You can set a custom [transition], define a Tween [curve], |
323 | + /// and a transition [duration]. | ||
321 | /// | 324 | /// |
322 | /// You can send any type of value to the other route in the [arguments]. | 325 | /// You can send any type of value to the other route in the [arguments]. |
323 | /// | 326 | /// |
@@ -338,6 +341,7 @@ extension GetNavigation on GetInterface { | @@ -338,6 +341,7 @@ extension GetNavigation on GetInterface { | ||
338 | Widget page, { | 341 | Widget page, { |
339 | bool opaque = false, | 342 | bool opaque = false, |
340 | Transition transition, | 343 | Transition transition, |
344 | + Curve curve, | ||
341 | bool popGesture, | 345 | bool popGesture, |
342 | int id, | 346 | int id, |
343 | Object arguments, | 347 | Object arguments, |
@@ -359,7 +363,8 @@ extension GetNavigation on GetInterface { | @@ -359,7 +363,8 @@ extension GetNavigation on GetInterface { | ||
359 | fullscreenDialog: fullscreenDialog, | 363 | fullscreenDialog: fullscreenDialog, |
360 | popGesture: popGesture ?? defaultPopGesture, | 364 | popGesture: popGesture ?? defaultPopGesture, |
361 | transition: transition ?? defaultTransition, | 365 | transition: transition ?? defaultTransition, |
362 | - transitionDuration: duration ?? defaultDurationTransition)); | 366 | + curve: curve ?? defaultTransitionCurve, |
367 | + transitionDuration: duration ?? defaultTransitionDuration)); | ||
363 | } | 368 | } |
364 | 369 | ||
365 | /// **Navigation.pushAndRemoveUntil()** shortcut .<br><br> | 370 | /// **Navigation.pushAndRemoveUntil()** shortcut .<br><br> |
@@ -370,7 +375,7 @@ extension GetNavigation on GetInterface { | @@ -370,7 +375,7 @@ extension GetNavigation on GetInterface { | ||
370 | /// It has the advantage of not needing context, | 375 | /// It has the advantage of not needing context, |
371 | /// so you can call from your business logic | 376 | /// so you can call from your business logic |
372 | /// | 377 | /// |
373 | - /// You can set a custom [transition], and a transition [duration]. | 378 | + /// You can set a custom [transition], a [curve] and a transition [duration]. |
374 | /// | 379 | /// |
375 | /// You can send any type of value to the other route in the [arguments]. | 380 | /// You can send any type of value to the other route in the [arguments]. |
376 | /// | 381 | /// |
@@ -401,8 +406,9 @@ extension GetNavigation on GetInterface { | @@ -401,8 +406,9 @@ extension GetNavigation on GetInterface { | ||
401 | Object arguments, | 406 | Object arguments, |
402 | Bindings binding, | 407 | Bindings binding, |
403 | bool fullscreenDialog = false, | 408 | bool fullscreenDialog = false, |
404 | - Duration duration, | ||
405 | Transition transition, | 409 | Transition transition, |
410 | + Curve curve, | ||
411 | + Duration duration, | ||
406 | }) { | 412 | }) { |
407 | var route = (Route<dynamic> rota) => false; | 413 | var route = (Route<dynamic> rota) => false; |
408 | 414 | ||
@@ -418,12 +424,16 @@ extension GetNavigation on GetInterface { | @@ -418,12 +424,16 @@ extension GetNavigation on GetInterface { | ||
418 | fullscreenDialog: fullscreenDialog, | 424 | fullscreenDialog: fullscreenDialog, |
419 | routeName: routename, | 425 | routeName: routename, |
420 | transition: transition ?? defaultTransition, | 426 | transition: transition ?? defaultTransition, |
421 | - transitionDuration: duration ?? defaultDurationTransition, | 427 | + curve: curve ?? defaultTransitionCurve, |
428 | + transitionDuration: duration ?? defaultTransitionDuration, | ||
422 | ), | 429 | ), |
423 | predicate ?? route); | 430 | predicate ?? route); |
424 | } | 431 | } |
425 | 432 | ||
426 | - /// Show a dialog | 433 | + /// Show a dialog. |
434 | + /// You can pass a [transitionDuration] and/or [transitionCurve], | ||
435 | + /// overriding the defaults when the dialog shows up and closes. | ||
436 | + /// When the dialog closes, uses those animations in reverse. | ||
427 | Future<T> dialog<T>( | 437 | Future<T> dialog<T>( |
428 | Widget widget, { | 438 | Widget widget, { |
429 | bool barrierDismissible = true, | 439 | bool barrierDismissible = true, |
@@ -431,6 +441,8 @@ extension GetNavigation on GetInterface { | @@ -431,6 +441,8 @@ extension GetNavigation on GetInterface { | ||
431 | bool useSafeArea = true, | 441 | bool useSafeArea = true, |
432 | bool useRootNavigator = true, | 442 | bool useRootNavigator = true, |
433 | RouteSettings routeSettings, | 443 | RouteSettings routeSettings, |
444 | + Duration transitionDuration, | ||
445 | + Curve transitionCurve, | ||
434 | }) { | 446 | }) { |
435 | assert(widget != null); | 447 | assert(widget != null); |
436 | assert(barrierDismissible != null); | 448 | assert(barrierDismissible != null); |
@@ -456,12 +468,12 @@ extension GetNavigation on GetInterface { | @@ -456,12 +468,12 @@ extension GetNavigation on GetInterface { | ||
456 | barrierDismissible: barrierDismissible, | 468 | barrierDismissible: barrierDismissible, |
457 | barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel, | 469 | barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel, |
458 | barrierColor: barrierColor ?? Colors.black54, | 470 | barrierColor: barrierColor ?? Colors.black54, |
459 | - transitionDuration: const Duration(milliseconds: 150), | 471 | + transitionDuration: transitionDuration ?? defaultDialogTransitionDuration, |
460 | transitionBuilder: (context, animation, secondaryAnimation, child) { | 472 | transitionBuilder: (context, animation, secondaryAnimation, child) { |
461 | return FadeTransition( | 473 | return FadeTransition( |
462 | opacity: CurvedAnimation( | 474 | opacity: CurvedAnimation( |
463 | parent: animation, | 475 | parent: animation, |
464 | - curve: Curves.easeOut, | 476 | + curve: transitionCurve ?? defaultDialogTransitionCurve, |
465 | ), | 477 | ), |
466 | child: child, | 478 | child: child, |
467 | ); | 479 | ); |
@@ -856,7 +868,7 @@ extension GetNavigation on GetInterface { | @@ -856,7 +868,7 @@ extension GetNavigation on GetInterface { | ||
856 | } | 868 | } |
857 | 869 | ||
858 | if (defaultDurationTransition != null) { | 870 | if (defaultDurationTransition != null) { |
859 | - this.defaultDurationTransition = defaultDurationTransition; | 871 | + this.defaultTransitionDuration = defaultDurationTransition; |
860 | } | 872 | } |
861 | 873 | ||
862 | if (defaultGlobalState != null) { | 874 | if (defaultGlobalState != null) { |
@@ -4,6 +4,7 @@ import 'package:get/get.dart'; | @@ -4,6 +4,7 @@ import 'package:get/get.dart'; | ||
4 | import 'package:get/src/core/log.dart'; | 4 | import 'package:get/src/core/log.dart'; |
5 | import 'package:get/src/instance/get_instance.dart'; | 5 | import 'package:get/src/instance/get_instance.dart'; |
6 | import 'package:get/src/navigation/routes/get_route.dart'; | 6 | import 'package:get/src/navigation/routes/get_route.dart'; |
7 | + | ||
7 | import 'root_controller.dart'; | 8 | import 'root_controller.dart'; |
8 | import 'smart_management.dart'; | 9 | import 'smart_management.dart'; |
9 | 10 | ||
@@ -209,7 +210,7 @@ class GetMaterialApp extends StatelessWidget { | @@ -209,7 +210,7 @@ class GetMaterialApp extends StatelessWidget { | ||
209 | defaultOpaqueRoute: opaqueRoute ?? Get.isOpaqueRouteDefault, | 210 | defaultOpaqueRoute: opaqueRoute ?? Get.isOpaqueRouteDefault, |
210 | defaultPopGesture: popGesture ?? Get.isPopGestureEnable, | 211 | defaultPopGesture: popGesture ?? Get.isPopGestureEnable, |
211 | defaultDurationTransition: | 212 | defaultDurationTransition: |
212 | - transitionDuration ?? Get.defaultDurationTransition, | 213 | + transitionDuration ?? Get.defaultTransitionDuration, |
213 | defaultGlobalState: defaultGlobalState ?? Get.defaultGlobalState, | 214 | defaultGlobalState: defaultGlobalState ?? Get.defaultGlobalState, |
214 | ); | 215 | ); |
215 | }, | 216 | }, |
-
Please register or login to post a comment