fixed GetPages.curve
- fixes #465 - iOS has an exception to the rule, when no Curve is defined, it doesn't use linearTransition in `CupertinoPages` (`Transition.cupertino/native/default`) and fullscreen dialogs so it applies the Curve, or use the default one. It might be smarter, maybe, to also enforce the `animation` duration to stay in platforms defaults. - had to change `CupertinoTransitions.buildTransitions` params in order to make the check and keep the code change small.
Showing
2 changed files
with
21 additions
and
35 deletions
| 1 | import 'dart:math'; | 1 | import 'dart:math'; | 
| 2 | import 'dart:ui' show lerpDouble; | 2 | import 'dart:ui' show lerpDouble; | 
| 3 | + | ||
| 3 | import 'package:flutter/cupertino.dart'; | 4 | import 'package:flutter/cupertino.dart'; | 
| 4 | import 'package:flutter/gestures.dart'; | 5 | import 'package:flutter/gestures.dart'; | 
| 5 | import 'package:flutter/material.dart'; | 6 | import 'package:flutter/material.dart'; | 
| @@ -7,6 +8,7 @@ import 'package:get/route_manager.dart'; | @@ -7,6 +8,7 @@ import 'package:get/route_manager.dart'; | ||
| 7 | import 'package:get/src/core/get_main.dart'; | 8 | import 'package:get/src/core/get_main.dart'; | 
| 8 | import 'package:get/src/instance/get_instance.dart'; | 9 | import 'package:get/src/instance/get_instance.dart'; | 
| 9 | import 'package:get/utils.dart'; | 10 | import 'package:get/utils.dart'; | 
| 11 | + | ||
| 10 | import 'bindings_interface.dart'; | 12 | import 'bindings_interface.dart'; | 
| 11 | import 'custom_transition.dart'; | 13 | import 'custom_transition.dart'; | 
| 12 | import 'default_transitions.dart'; | 14 | import 'default_transitions.dart'; | 
| @@ -136,18 +138,24 @@ class GetPageRoute<T> extends PageRoute<T> { | @@ -136,18 +138,24 @@ class GetPageRoute<T> extends PageRoute<T> { | ||
| 136 | @override | 138 | @override | 
| 137 | Widget buildTransitions(BuildContext context, Animation<double> animation, | 139 | Widget buildTransitions(BuildContext context, Animation<double> animation, | 
| 138 | Animation<double> secondaryAnimation, Widget child) { | 140 | Animation<double> secondaryAnimation, Widget child) { | 
| 141 | + final finalCurve = curve ?? Get.defaultTransitionCurve; | ||
| 142 | + final hasCurve = curve != null; | ||
| 139 | if (fullscreenDialog && transition == null) { | 143 | if (fullscreenDialog && transition == null) { | 
| 144 | + /// by default, if no curve is defined, use Cupertino transition in the | ||
| 145 | + /// default way (no linearTransition)... otherwise take the curve passed. | ||
| 140 | return CupertinoFullscreenDialogTransition( | 146 | return CupertinoFullscreenDialogTransition( | 
| 141 | - primaryRouteAnimation: animation, | 147 | + primaryRouteAnimation: hasCurve | 
| 148 | + ? CurvedAnimation(parent: animation, curve: finalCurve) | ||
| 149 | + : animation, | ||
| 142 | secondaryRouteAnimation: secondaryAnimation, | 150 | secondaryRouteAnimation: secondaryAnimation, | 
| 143 | child: child, | 151 | child: child, | 
| 144 | - linearTransition: true); | 152 | + linearTransition: hasCurve); | 
| 145 | } | 153 | } | 
| 146 | 154 | ||
| 147 | if (this.customTransition != null) { | 155 | if (this.customTransition != null) { | 
| 148 | return this.customTransition.buildTransition( | 156 | return this.customTransition.buildTransition( | 
| 149 | context, | 157 | context, | 
| 150 | - curve, | 158 | + finalCurve, | 
| 151 | alignment, | 159 | alignment, | 
| 152 | animation, | 160 | animation, | 
| 153 | secondaryAnimation, | 161 | secondaryAnimation, | 
| @@ -159,6 +167,10 @@ class GetPageRoute<T> extends PageRoute<T> { | @@ -159,6 +167,10 @@ class GetPageRoute<T> extends PageRoute<T> { | ||
| 159 | : child); | 167 | : child); | 
| 160 | } | 168 | } | 
| 161 | 169 | ||
| 170 | + /// Apply the curve by default... | ||
| 171 | + final iosAnimation = animation; | ||
| 172 | + animation = CurvedAnimation(parent: animation, curve: finalCurve); | ||
| 173 | + | ||
| 162 | switch (transition ?? Get.defaultTransition) { | 174 | switch (transition ?? Get.defaultTransition) { | 
| 163 | case Transition.leftToRight: | 175 | case Transition.leftToRight: | 
| 164 | return SlideLeftTransition().buildTransitions( | 176 | return SlideLeftTransition().buildTransitions( | 
| @@ -283,9 +295,9 @@ class GetPageRoute<T> extends PageRoute<T> { | @@ -283,9 +295,9 @@ class GetPageRoute<T> extends PageRoute<T> { | ||
| 283 | case Transition.cupertino: | 295 | case Transition.cupertino: | 
| 284 | return CupertinoTransitions().buildTransitions( | 296 | return CupertinoTransitions().buildTransitions( | 
| 285 | context, | 297 | context, | 
| 286 | - curve, | 298 | + hasCurve, | 
| 287 | alignment, | 299 | alignment, | 
| 288 | - animation, | 300 | + hasCurve ? animation : iosAnimation, | 
| 289 | secondaryAnimation, | 301 | secondaryAnimation, | 
| 290 | popGesture ?? Get.defaultPopGesture | 302 | popGesture ?? Get.defaultPopGesture | 
| 291 | ? _CupertinoBackGestureDetector<T>( | 303 | ? _CupertinoBackGestureDetector<T>( | 
| @@ -335,39 +347,13 @@ class GetPageRoute<T> extends PageRoute<T> { | @@ -335,39 +347,13 @@ class GetPageRoute<T> extends PageRoute<T> { | ||
| 335 | : child); | 347 | : child); | 
| 336 | 348 | ||
| 337 | case Transition.native: | 349 | case Transition.native: | 
| 338 | - if (GetPlatform.isIOS) | ||
| 339 | - return CupertinoTransitions().buildTransitions( | ||
| 340 | - context, | ||
| 341 | - curve, | ||
| 342 | - alignment, | ||
| 343 | - animation, | ||
| 344 | - secondaryAnimation, | ||
| 345 | - popGesture ?? Get.defaultPopGesture | ||
| 346 | - ? _CupertinoBackGestureDetector<T>( | ||
| 347 | - enabledCallback: () => _isPopGestureEnabled<T>(this), | ||
| 348 | - onStartPopGesture: () => _startPopGesture<T>(this), | ||
| 349 | - child: child) | ||
| 350 | - : child); | ||
| 351 | - | ||
| 352 | - return FadeUpwardsPageTransitionsBuilder().buildTransitions( | ||
| 353 | - this, | ||
| 354 | - context, | ||
| 355 | - animation, | ||
| 356 | - secondaryAnimation, | ||
| 357 | - popGesture ?? Get.defaultPopGesture | ||
| 358 | - ? _CupertinoBackGestureDetector<T>( | ||
| 359 | - enabledCallback: () => _isPopGestureEnabled<T>(this), | ||
| 360 | - onStartPopGesture: () => _startPopGesture<T>(this), | ||
| 361 | - child: child) | ||
| 362 | - : child); | ||
| 363 | - | ||
| 364 | default: | 350 | default: | 
| 365 | if (GetPlatform.isIOS) | 351 | if (GetPlatform.isIOS) | 
| 366 | return CupertinoTransitions().buildTransitions( | 352 | return CupertinoTransitions().buildTransitions( | 
| 367 | context, | 353 | context, | 
| 368 | - curve, | 354 | + hasCurve, | 
| 369 | alignment, | 355 | alignment, | 
| 370 | - animation, | 356 | + hasCurve ? animation : iosAnimation, | 
| 371 | secondaryAnimation, | 357 | secondaryAnimation, | 
| 372 | popGesture ?? Get.defaultPopGesture | 358 | popGesture ?? Get.defaultPopGesture | 
| 373 | ? _CupertinoBackGestureDetector<T>( | 359 | ? _CupertinoBackGestureDetector<T>( | 
| @@ -188,7 +188,7 @@ class SizeTransitions { | @@ -188,7 +188,7 @@ class SizeTransitions { | ||
| 188 | class CupertinoTransitions { | 188 | class CupertinoTransitions { | 
| 189 | Widget buildTransitions( | 189 | Widget buildTransitions( | 
| 190 | BuildContext context, | 190 | BuildContext context, | 
| 191 | - Curve curve, | 191 | + bool useLinearTransition, | 
| 192 | Alignment alignment, | 192 | Alignment alignment, | 
| 193 | Animation<double> animation, | 193 | Animation<double> animation, | 
| 194 | Animation<double> secondaryAnimation, | 194 | Animation<double> secondaryAnimation, | 
| @@ -196,7 +196,7 @@ class CupertinoTransitions { | @@ -196,7 +196,7 @@ class CupertinoTransitions { | ||
| 196 | return CupertinoPageTransition( | 196 | return CupertinoPageTransition( | 
| 197 | primaryRouteAnimation: animation, | 197 | primaryRouteAnimation: animation, | 
| 198 | secondaryRouteAnimation: secondaryAnimation, | 198 | secondaryRouteAnimation: secondaryAnimation, | 
| 199 | - linearTransition: true, | 199 | + linearTransition: useLinearTransition, | 
| 200 | child: child, | 200 | child: child, | 
| 201 | ); | 201 | ); | 
| 202 | } | 202 | } | 
- 
Please register or login to post a comment