Jonny Borges
Committed by GitHub

Add files via upload

@@ -147,6 +147,13 @@ @@ -147,6 +147,13 @@
147 -Added setKey to improve modular compatibility 147 -Added setKey to improve modular compatibility
148 -Added ability to define transition duration directly when calling the new route. 148 -Added ability to define transition duration directly when calling the new route.
149 149
  150 +## [1.11.0]
  151 + -Added experimental GetCupertino
  152 +
  153 +## [1.11.1]
  154 + -Improve swipe to back on iOS devices
  155 +
  156 +
150 157
151 158
152 159
@@ -17,7 +17,7 @@ Add this to your package's pubspec.yaml file: @@ -17,7 +17,7 @@ Add this to your package's pubspec.yaml file:
17 17
18 ``` 18 ```
19 dependencies: 19 dependencies:
20 - get: ^1.10.5 20 + get: ^1.11.1
21 ``` 21 ```
22 22
23 And import it: 23 And import it:
@@ -28,7 +28,6 @@ Add GetKey to your MaterialApp and enjoy: @@ -28,7 +28,6 @@ Add GetKey to your MaterialApp and enjoy:
28 ```dart 28 ```dart
29 MaterialApp( 29 MaterialApp(
30 navigatorKey: Get.key, 30 navigatorKey: Get.key,
31 - // navigatorKey: Get.addKey(Modular.navigatorKey), // to modular users  
32 home: MyHome(), 31 home: MyHome(),
33 ) 32 )
34 ``` 33 ```
@@ -252,8 +251,6 @@ class MiddleWare { @@ -252,8 +251,6 @@ class MiddleWare {
252 251
253 ### COPY THE ROUTER CLASS BELOW: 252 ### COPY THE ROUTER CLASS BELOW:
254 Copy this Router class below and put it in your app, rename routes and classes for your own, add more classes to it if necessary. 253 Copy this Router class below and put it in your app, rename routes and classes for your own, add more classes to it if necessary.
255 -#### Important!!!  
256 -GetRoute has great performance optimizations that MaterialPageRoute and CupertinoPageRoute do not. It solves the main problems with memory leaks and unexpected reconstructions of the Flutter, so please do not insert MaterialPageRoute or CupertinoPageRoute here, or you will lose one of the main benefits of this lib, in addition to experiencing inconsistencies in the transitions. We recommend always using GetRoute, and if you need custom transitions, use PageRouteBuilder by adding the parameter 'opaque = false' to maintain compatibility with the library.  
257 254
258 ```dart 255 ```dart
259 class Router { 256 class Router {
@@ -284,6 +281,35 @@ class Router { @@ -284,6 +281,35 @@ class Router {
284 } 281 }
285 } 282 }
286 ``` 283 ```
  284 +##### Experimental
  285 +If you need specific Cupertino elements, such as dragging to close, you can use GetCupertino:
  286 +```dart
  287 +class Router {
  288 + static Route<dynamic> generateRoute(RouteSettings settings) {
  289 + switch (settings.name) {
  290 + case '/':
  291 + return GetCupertino(
  292 + page: First(),
  293 + settings: settings,
  294 + );
  295 + case '/second':
  296 + return GetCupertino(
  297 + settings: settings, page: Second());
  298 + case '/third':
  299 + return GetCupertino(
  300 + settings: settings,
  301 + page: Third());
  302 + default:
  303 + return GetCupertino(
  304 + settings: settings,
  305 + page: Scaffold(
  306 + body:
  307 + Center(child: Text('No route defined for ${settings.name}')),
  308 + ));
  309 + }
  310 + }
  311 +}
  312 +```
287 And now, all you need to do is use Get.toNamed() to navigate your named routes, without any context (BLoC will love it), and when your app is compiled to the web, your routes will appear in the url beautifully <3 313 And now, all you need to do is use Get.toNamed() to navigate your named routes, without any context (BLoC will love it), and when your app is compiled to the web, your routes will appear in the url beautifully <3
288 314
289 ```dart 315 ```dart
1 import 'package:flutter/material.dart'; 1 import 'package:flutter/material.dart';
2 import 'package:get/get.dart'; 2 import 'package:get/get.dart';
3 3
4 -void main() {  
5 - runApp(MaterialApp(  
6 - title: 'Navigation Basics', 4 +void main() => runApp(MyApp());
  5 +
  6 +class MyApp extends StatelessWidget {
  7 + @override
  8 + Widget build(BuildContext context) {
  9 + return MaterialApp(
7 navigatorKey: Get.key, 10 navigatorKey: Get.key,
8 - home: FirstRoute(),  
9 - )); 11 + initialRoute: "/",
  12 + navigatorObservers: [
  13 + GetObserver(MiddleWare.observer),
  14 + ],
  15 + onGenerateRoute: Router.generateRoute,
  16 + );
  17 + }
  18 +}
  19 +
  20 +class MiddleWare {
  21 + static observer(Routing routing) {
  22 + ///Trigger any event when a route is pushed or popped by Get.
  23 + /// You can listen in addition to the routes, the snackbars, dialogs and bottomsheets on each screen.
  24 + ///If you need to enter any of these 3 events directly here,
  25 + ///you must specify that the event is != Than you are trying to do.
  26 + if (routing.current == '/second' && !routing.isSnackbar) {
  27 + Get.snackbar("Hi", "You are on second route");
  28 + } else if (routing.current =='/third'){
  29 + print('last route called');
  30 + }
  31 + }
10 } 32 }
11 33
12 -class FirstRoute extends StatelessWidget { 34 +class First extends StatelessWidget {
13 @override 35 @override
14 Widget build(BuildContext context) { 36 Widget build(BuildContext context) {
15 return Scaffold( 37 return Scaffold(
16 appBar: AppBar( 38 appBar: AppBar(
  39 + leading: IconButton(
  40 + icon: Icon(Icons.add),
  41 + onPressed: () {
  42 + Get.snackbar("hi", "i am a modern snackbar");
  43 + },
  44 + ),
17 title: Text('First Route'), 45 title: Text('First Route'),
18 ), 46 ),
19 body: Center( 47 body: Center(
20 child: RaisedButton( 48 child: RaisedButton(
21 child: Text('Open route'), 49 child: Text('Open route'),
22 onPressed: () { 50 onPressed: () {
23 - Get.to(SecondRoute()); 51 + Get.toNamed("/second");
  52 + },
  53 + ),
  54 + ),
  55 + );
  56 + }
  57 +}
  58 +
  59 +class Second extends StatelessWidget {
  60 + @override
  61 + Widget build(BuildContext context) {
  62 + return Scaffold(
  63 + appBar: AppBar(
  64 + leading: IconButton(
  65 + icon: Icon(Icons.add),
  66 + onPressed: () {
  67 + Get.snackbar("hi", "i am a modern snackbar");
  68 + },
  69 + ),
  70 + title: Text('second Route'),
  71 + ),
  72 + body: Center(
  73 + child: RaisedButton(
  74 + child: Text('Open route'),
  75 + onPressed: () {
  76 + Get.toNamed("/third");
24 }, 77 },
25 ), 78 ),
26 ), 79 ),
@@ -28,12 +81,12 @@ class FirstRoute extends StatelessWidget { @@ -28,12 +81,12 @@ class FirstRoute extends StatelessWidget {
28 } 81 }
29 } 82 }
30 83
31 -class SecondRoute extends StatelessWidget { 84 +class Third extends StatelessWidget {
32 @override 85 @override
33 Widget build(BuildContext context) { 86 Widget build(BuildContext context) {
34 return Scaffold( 87 return Scaffold(
35 appBar: AppBar( 88 appBar: AppBar(
36 - title: Text("Second Route"), 89 + title: Text("Third Route"),
37 ), 90 ),
38 body: Center( 91 body: Center(
39 child: RaisedButton( 92 child: RaisedButton(
@@ -52,21 +105,21 @@ class Router { @@ -52,21 +105,21 @@ class Router {
52 switch (settings.name) { 105 switch (settings.name) {
53 case '/': 106 case '/':
54 return GetRoute( 107 return GetRoute(
55 - page: SplashScreen(), 108 + page: First(),
56 settings: settings, 109 settings: settings,
57 ); 110 );
58 - case '/Home': 111 + case '/second':
59 return GetRoute( 112 return GetRoute(
60 - settings: settings, page: Home(), transition: Transition.fade);  
61 - case '/Chat': 113 + settings: settings, page: Second(), transition: Transition.fade);
  114 + case '/third':
62 return GetRoute( 115 return GetRoute(
63 settings: settings, 116 settings: settings,
64 - page: Chat(), 117 + page: Third(),
65 transition: Transition.rightToLeft); 118 transition: Transition.rightToLeft);
66 default: 119 default:
67 return GetRoute( 120 return GetRoute(
68 settings: settings, 121 settings: settings,
69 - transition: Transition.rotate, 122 + transition: Transition.fade,
70 page: Scaffold( 123 page: Scaffold(
71 body: 124 body:
72 Center(child: Text('No route defined for ${settings.name}')), 125 Center(child: Text('No route defined for ${settings.name}')),
@@ -80,7 +80,7 @@ packages: @@ -80,7 +80,7 @@ packages:
80 name: get 80 name: get
81 url: "https://pub.dartlang.org" 81 url: "https://pub.dartlang.org"
82 source: hosted 82 source: hosted
83 - version: "1.8.0" 83 + version: "1.10.0"
84 image: 84 image:
85 dependency: transitive 85 dependency: transitive
86 description: 86 description:
@@ -6,3 +6,5 @@ export 'src/snack.dart'; @@ -6,3 +6,5 @@ export 'src/snack.dart';
6 export 'src/bottomsheet.dart'; 6 export 'src/bottomsheet.dart';
7 export 'src/snack_route.dart'; 7 export 'src/snack_route.dart';
8 export 'src/route_observer.dart'; 8 export 'src/route_observer.dart';
  9 +export 'src/getroute_cupertino.dart';
  10 +export 'src/transitions_type.dart';
1 import 'package:flutter/material.dart'; 1 import 'package:flutter/material.dart';
2 2
  3 +import 'transitions_type.dart';
  4 +
3 class GetRoute<T> extends PageRouteBuilder<T> { 5 class GetRoute<T> extends PageRouteBuilder<T> {
4 /// Construct a Modified PageRoute whose contents are defined by child. 6 /// Construct a Modified PageRoute whose contents are defined by child.
5 /// The values of [child], [maintainState], [opaque], and [fullScreenDialog] must not 7 /// The values of [child], [maintainState], [opaque], and [fullScreenDialog] must not
@@ -221,16 +223,3 @@ class GetRoute<T> extends PageRouteBuilder<T> { @@ -221,16 +223,3 @@ class GetRoute<T> extends PageRouteBuilder<T> {
221 223
222 final Duration duration; 224 final Duration duration;
223 } 225 }
224 -  
225 -enum Transition {  
226 - fade,  
227 - rightToLeft,  
228 - leftToRight,  
229 - upToDown,  
230 - downToUp,  
231 - scale,  
232 - rotate,  
233 - size,  
234 - rightToLeftWithFade,  
235 - leftToRightWithFade,  
236 -}  
  1 +import 'dart:math';
  2 +import 'dart:ui' show lerpDouble;
  3 +
  4 +import 'package:flutter/cupertino.dart';
  5 +import 'package:flutter/foundation.dart';
  6 +import 'package:flutter/gestures.dart';
  7 +
  8 +import 'transitions_type.dart';
  9 +
  10 +const double _kBackGestureWidth = 20.0;
  11 +const double _kMinFlingVelocity = 1.0;
  12 +const int _kMaxDroppedSwipePageForwardAnimationTime = 800; // Milliseconds.
  13 +
  14 +// The maximum time for a page to get reset to it's original position if the
  15 +// user releases a page mid swipe.
  16 +const int _kMaxPageBackAnimationTime = 300;
  17 +
  18 +class GetCupertino<T> extends PageRoute<T> {
  19 + /// Creates a page route for use in an iOS designed app.
  20 + ///
  21 + /// The [builder], [maintainState], and [fullscreenDialog] arguments must not
  22 + /// be null.
  23 + GetCupertino({
  24 + @required this.page,
  25 + this.title,
  26 + RouteSettings settings,
  27 + this.maintainState = true,
  28 + this.curve = Curves.linear,
  29 + this.alignment,
  30 + this.opaque = false,
  31 + this.transition = Transition.cupertino,
  32 + this.duration = const Duration(milliseconds: 400),
  33 + bool fullscreenDialog = false,
  34 + }) : assert(page != null),
  35 + assert(maintainState != null),
  36 + assert(fullscreenDialog != null),
  37 + // assert(opaque),
  38 + super(settings: settings, fullscreenDialog: fullscreenDialog);
  39 +
  40 + /// Builds the primary contents of the route.
  41 + final Widget page;
  42 +
  43 + final Duration duration;
  44 +
  45 + final String title;
  46 +
  47 + final Transition transition;
  48 +
  49 + final Curve curve;
  50 +
  51 + final Alignment alignment;
  52 +
  53 + ValueNotifier<String> _previousTitle;
  54 +
  55 + /// The title string of the previous [GetCupertino].
  56 + ///
  57 + /// The [ValueListenable]'s value is readable after the route is installed
  58 + /// onto a [Navigator]. The [ValueListenable] will also notify its listeners
  59 + /// if the value changes (such as by replacing the previous route).
  60 + ///
  61 + /// The [ValueListenable] itself will be null before the route is installed.
  62 + /// Its content value will be null if the previous route has no title or
  63 + /// is not a [GetCupertino].
  64 + ///
  65 + /// See also:
  66 + ///
  67 + /// * [ValueListenableBuilder], which can be used to listen and rebuild
  68 + /// widgets based on a ValueListenable.
  69 + ValueListenable<String> get previousTitle {
  70 + assert(
  71 + _previousTitle != null,
  72 + 'Cannot read the previousTitle for a route that has not yet been installed',
  73 + );
  74 + return _previousTitle;
  75 + }
  76 +
  77 + @override
  78 + void didChangePrevious(Route<dynamic> previousRoute) {
  79 + final String previousTitleString =
  80 + previousRoute is GetCupertino ? previousRoute.title : null;
  81 + if (_previousTitle == null) {
  82 + _previousTitle = ValueNotifier<String>(previousTitleString);
  83 + } else {
  84 + _previousTitle.value = previousTitleString;
  85 + }
  86 + super.didChangePrevious(previousRoute);
  87 + }
  88 +
  89 + @override
  90 + final bool maintainState;
  91 +
  92 + /// Allows you to set opaque to false to prevent route reconstruction.
  93 + @override
  94 + final bool opaque;
  95 +
  96 + @override
  97 + // A relatively rigorous eyeball estimation.
  98 + Duration get transitionDuration => const Duration(milliseconds: 400);
  99 +
  100 + @override
  101 + Color get barrierColor => null;
  102 +
  103 + @override
  104 + String get barrierLabel => null;
  105 +
  106 + @override
  107 + bool canTransitionTo(TransitionRoute<dynamic> nextRoute) {
  108 + // Don't perform outgoing animation if the next route is a fullscreen dialog.
  109 + return nextRoute is GetCupertino && !nextRoute.fullscreenDialog;
  110 + }
  111 +
  112 + /// True if an iOS-style back swipe pop gesture is currently underway for [route].
  113 + ///
  114 + /// This just check the route's [NavigatorState.userGestureInProgress].
  115 + ///
  116 + /// See also:
  117 + ///
  118 + /// * [popGestureEnabled], which returns true if a user-triggered pop gesture
  119 + /// would be allowed.
  120 + static bool isPopGestureInProgress(PageRoute<dynamic> route) {
  121 + return route.navigator.userGestureInProgress;
  122 + }
  123 +
  124 + /// True if an iOS-style back swipe pop gesture is currently underway for this route.
  125 + ///
  126 + /// See also:
  127 + ///
  128 + /// * [isPopGestureInProgress], which returns true if a Cupertino pop gesture
  129 + /// is currently underway for specific route.
  130 + /// * [popGestureEnabled], which returns true if a user-triggered pop gesture
  131 + /// would be allowed.
  132 + bool get popGestureInProgress => isPopGestureInProgress(this);
  133 +
  134 + /// Whether a pop gesture can be started by the user.
  135 + ///
  136 + /// Returns true if the user can edge-swipe to a previous route.
  137 + ///
  138 + /// Returns false once [isPopGestureInProgress] is true, but
  139 + /// [isPopGestureInProgress] can only become true if [popGestureEnabled] was
  140 + /// true first.
  141 + ///
  142 + /// This should only be used between frames, not during build.
  143 + bool get popGestureEnabled => _isPopGestureEnabled(this);
  144 +
  145 + static bool _isPopGestureEnabled<T>(PageRoute<T> route) {
  146 + // If there's nothing to go back to, then obviously we don't support
  147 + // the back gesture.
  148 + if (route.isFirst) return false;
  149 + // If the route wouldn't actually pop if we popped it, then the gesture
  150 + // would be really confusing (or would skip internal routes), so disallow it.
  151 + if (route.willHandlePopInternally) return false;
  152 + // If attempts to dismiss this route might be vetoed such as in a page
  153 + // with forms, then do not allow the user to dismiss the route with a swipe.
  154 + if (route.hasScopedWillPopCallback) return false;
  155 + // Fullscreen dialogs aren't dismissible by back swipe.
  156 + if (route.fullscreenDialog) return false;
  157 + // If we're in an animation already, we cannot be manually swiped.
  158 + if (route.animation.status != AnimationStatus.completed) return false;
  159 + // If we're being popped into, we also cannot be swiped until the pop above
  160 + // it completes. This translates to our secondary animation being
  161 + // dismissed.
  162 + if (route.secondaryAnimation.status != AnimationStatus.dismissed)
  163 + return false;
  164 + // If we're in a gesture already, we cannot start another.
  165 + if (isPopGestureInProgress(route)) return false;
  166 +
  167 + // Looks like a back gesture would be welcome!
  168 + return true;
  169 + }
  170 +
  171 + @override
  172 + Widget buildPage(BuildContext context, Animation<double> animation,
  173 + Animation<double> secondaryAnimation) {
  174 + final Widget child = page;
  175 + final Widget result = Semantics(
  176 + scopesRoute: true,
  177 + explicitChildNodes: true,
  178 + child: child,
  179 + );
  180 + assert(() {
  181 + if (child == null) {
  182 + throw FlutterError.fromParts(<DiagnosticsNode>[
  183 + ErrorSummary(
  184 + 'The builder for route "${settings.name}" returned null.'),
  185 + ErrorDescription('Route builders must never return null.'),
  186 + ]);
  187 + }
  188 + return true;
  189 + }());
  190 + return result;
  191 + }
  192 +
  193 + // Called by _CupertinoBackGestureDetector when a pop ("back") drag start
  194 + // gesture is detected. The returned controller handles all of the subsequent
  195 + // drag events.
  196 + static _CupertinoBackGestureController<T> _startPopGesture<T>(
  197 + PageRoute<T> route) {
  198 + assert(_isPopGestureEnabled(route));
  199 +
  200 + return _CupertinoBackGestureController<T>(
  201 + navigator: route.navigator,
  202 + controller: route.controller, // protected access
  203 + );
  204 + }
  205 +
  206 + /// Returns a [CupertinoFullscreenDialogTransition] if [route] is a full
  207 + /// screen dialog, otherwise a [CupertinoPageTransition] is returned.
  208 + ///
  209 + /// Used by [GetCupertino.buildTransitions].
  210 + ///
  211 + /// This method can be applied to any [PageRoute], not just
  212 + /// [GetCupertino]. It's typically used to provide a Cupertino style
  213 + /// horizontal transition for material widgets when the target platform
  214 + /// is [TargetPlatform.iOS].
  215 + ///
  216 + /// See also:
  217 + ///
  218 + /// * [CupertinoPageTransitionsBuilder], which uses this method to define a
  219 + /// [PageTransitionsBuilder] for the [PageTransitionsTheme].
  220 + static Widget buildPageTransitions<T>(
  221 + PageRoute<T> route,
  222 + BuildContext context,
  223 + Animation<double> animation,
  224 + Animation<double> secondaryAnimation,
  225 + Widget child,
  226 + Transition transition,
  227 + Curve curve,
  228 + Alignment alignment,
  229 + ) {
  230 + if (route.fullscreenDialog) {
  231 + return CupertinoFullscreenDialogTransition(
  232 + animation: animation,
  233 + child: child,
  234 + );
  235 + } else {
  236 + switch (transition) {
  237 + case Transition.fade:
  238 + return FadeTransition(
  239 + opacity: animation,
  240 + child: _CupertinoBackGestureDetector<T>(
  241 + enabledCallback: () => _isPopGestureEnabled<T>(route),
  242 + onStartPopGesture: () => _startPopGesture<T>(route),
  243 + child: child,
  244 + ),
  245 + );
  246 + break;
  247 + case Transition.rightToLeft:
  248 + return SlideTransition(
  249 + transformHitTests: false,
  250 + position: new Tween<Offset>(
  251 + begin: const Offset(1.0, 0.0),
  252 + end: Offset.zero,
  253 + ).animate(animation),
  254 + child: new SlideTransition(
  255 + position: new Tween<Offset>(
  256 + begin: Offset.zero,
  257 + end: const Offset(-1.0, 0.0),
  258 + ).animate(secondaryAnimation),
  259 + child: _CupertinoBackGestureDetector<T>(
  260 + enabledCallback: () => _isPopGestureEnabled<T>(route),
  261 + onStartPopGesture: () => _startPopGesture<T>(route),
  262 + child: child,
  263 + ),
  264 + ),
  265 + );
  266 + break;
  267 + case Transition.leftToRight:
  268 + return SlideTransition(
  269 + transformHitTests: false,
  270 + position: Tween<Offset>(
  271 + begin: const Offset(-1.0, 0.0),
  272 + end: Offset.zero,
  273 + ).animate(animation),
  274 + child: new SlideTransition(
  275 + position: new Tween<Offset>(
  276 + begin: Offset.zero,
  277 + end: const Offset(1.0, 0.0),
  278 + ).animate(secondaryAnimation),
  279 + child: _CupertinoBackGestureDetector<T>(
  280 + enabledCallback: () => _isPopGestureEnabled<T>(route),
  281 + onStartPopGesture: () => _startPopGesture<T>(route),
  282 + child: child,
  283 + ),
  284 + ),
  285 + );
  286 + break;
  287 + case Transition.upToDown:
  288 + return SlideTransition(
  289 + transformHitTests: false,
  290 + position: Tween<Offset>(
  291 + begin: const Offset(0.0, -1.0),
  292 + end: Offset.zero,
  293 + ).animate(animation),
  294 + child: new SlideTransition(
  295 + position: new Tween<Offset>(
  296 + begin: Offset.zero,
  297 + end: const Offset(0.0, 1.0),
  298 + ).animate(secondaryAnimation),
  299 + child: _CupertinoBackGestureDetector<T>(
  300 + enabledCallback: () => _isPopGestureEnabled<T>(route),
  301 + onStartPopGesture: () => _startPopGesture<T>(route),
  302 + child: child,
  303 + ),
  304 + ),
  305 + );
  306 + break;
  307 + case Transition.downToUp:
  308 + return SlideTransition(
  309 + transformHitTests: false,
  310 + position: Tween<Offset>(
  311 + begin: const Offset(0.0, 1.0),
  312 + end: Offset.zero,
  313 + ).animate(animation),
  314 + child: new SlideTransition(
  315 + position: new Tween<Offset>(
  316 + begin: Offset.zero,
  317 + end: const Offset(0.0, -1.0),
  318 + ).animate(secondaryAnimation),
  319 + child: _CupertinoBackGestureDetector<T>(
  320 + enabledCallback: () => _isPopGestureEnabled<T>(route),
  321 + onStartPopGesture: () => _startPopGesture<T>(route),
  322 + child: child,
  323 + ),
  324 + ),
  325 + );
  326 + break;
  327 + case Transition.scale:
  328 + return ScaleTransition(
  329 + alignment: alignment,
  330 + scale: CurvedAnimation(
  331 + parent: animation,
  332 + curve: Interval(
  333 + 0.00,
  334 + 0.50,
  335 + curve: curve,
  336 + ),
  337 + ),
  338 + child: _CupertinoBackGestureDetector<T>(
  339 + enabledCallback: () => _isPopGestureEnabled<T>(route),
  340 + onStartPopGesture: () => _startPopGesture<T>(route),
  341 + child: child,
  342 + ),
  343 + );
  344 + break;
  345 + case Transition.rotate:
  346 + return RotationTransition(
  347 + alignment: alignment,
  348 + turns: animation,
  349 + child: ScaleTransition(
  350 + alignment: alignment,
  351 + scale: animation,
  352 + child: FadeTransition(
  353 + opacity: animation,
  354 + child: _CupertinoBackGestureDetector<T>(
  355 + enabledCallback: () => _isPopGestureEnabled<T>(route),
  356 + onStartPopGesture: () => _startPopGesture<T>(route),
  357 + child: child,
  358 + ),
  359 + ),
  360 + ),
  361 + );
  362 + break;
  363 + case Transition.size:
  364 + return Align(
  365 + alignment: alignment,
  366 + child: SizeTransition(
  367 + sizeFactor: CurvedAnimation(
  368 + parent: animation,
  369 + curve: curve,
  370 + ),
  371 + child: _CupertinoBackGestureDetector<T>(
  372 + enabledCallback: () => _isPopGestureEnabled<T>(route),
  373 + onStartPopGesture: () => _startPopGesture<T>(route),
  374 + child: child,
  375 + ),
  376 + ),
  377 + );
  378 + break;
  379 + case Transition.rightToLeftWithFade:
  380 + return SlideTransition(
  381 + position: Tween<Offset>(
  382 + begin: const Offset(1.0, 0.0),
  383 + end: Offset.zero,
  384 + ).animate(animation),
  385 + child: FadeTransition(
  386 + opacity: animation,
  387 + child: SlideTransition(
  388 + position: Tween<Offset>(
  389 + begin: Offset.zero,
  390 + end: const Offset(-1.0, 0.0),
  391 + ).animate(secondaryAnimation),
  392 + child: _CupertinoBackGestureDetector<T>(
  393 + enabledCallback: () => _isPopGestureEnabled<T>(route),
  394 + onStartPopGesture: () => _startPopGesture<T>(route),
  395 + child: child,
  396 + ),
  397 + ),
  398 + ),
  399 + );
  400 + break;
  401 + case Transition.leftToRightWithFade:
  402 + return SlideTransition(
  403 + position: Tween<Offset>(
  404 + begin: const Offset(-1.0, 0.0),
  405 + end: Offset.zero,
  406 + ).animate(animation),
  407 + child: FadeTransition(
  408 + opacity: animation,
  409 + child: SlideTransition(
  410 + position: Tween<Offset>(
  411 + begin: Offset.zero,
  412 + end: const Offset(1.0, 0.0),
  413 + ).animate(secondaryAnimation),
  414 + child: _CupertinoBackGestureDetector<T>(
  415 + enabledCallback: () => _isPopGestureEnabled<T>(route),
  416 + onStartPopGesture: () => _startPopGesture<T>(route),
  417 + child: child,
  418 + ),
  419 + ),
  420 + ),
  421 + );
  422 + break;
  423 + case Transition.cupertino:
  424 + return CupertinoPageTransition(
  425 + primaryRouteAnimation: animation,
  426 + secondaryRouteAnimation: secondaryAnimation,
  427 + // Check if the route has an animation that's currently participating
  428 + // in a back swipe gesture.
  429 + //
  430 + // In the middle of a back gesture drag, let the transition be linear to
  431 + // match finger motions.
  432 + linearTransition: isPopGestureInProgress(route),
  433 + child: _CupertinoBackGestureDetector<T>(
  434 + enabledCallback: () => _isPopGestureEnabled<T>(route),
  435 + onStartPopGesture: () => _startPopGesture<T>(route),
  436 + child: child,
  437 + ),
  438 + );
  439 + break;
  440 + default:
  441 + return CupertinoPageTransition(
  442 + primaryRouteAnimation: animation,
  443 + secondaryRouteAnimation: secondaryAnimation,
  444 + // Check if the route has an animation that's currently participating
  445 + // in a back swipe gesture.
  446 + //
  447 + // In the middle of a back gesture drag, let the transition be linear to
  448 + // match finger motions.
  449 + linearTransition: isPopGestureInProgress(route),
  450 + child: _CupertinoBackGestureDetector<T>(
  451 + enabledCallback: () => _isPopGestureEnabled<T>(route),
  452 + onStartPopGesture: () => _startPopGesture<T>(route),
  453 + child: child,
  454 + ),
  455 + );
  456 + }
  457 + }
  458 + }
  459 +
  460 + @override
  461 + Widget buildTransitions(BuildContext context, Animation<double> animation,
  462 + Animation<double> secondaryAnimation, Widget child) {
  463 + return buildPageTransitions<T>(this, context, animation, secondaryAnimation,
  464 + child, transition, curve, alignment);
  465 + }
  466 +
  467 + @override
  468 + String get debugLabel => '${super.debugLabel}(${settings.name})';
  469 +}
  470 +
  471 +class _CupertinoBackGestureDetector<T> extends StatefulWidget {
  472 + const _CupertinoBackGestureDetector({
  473 + Key key,
  474 + @required this.enabledCallback,
  475 + @required this.onStartPopGesture,
  476 + @required this.child,
  477 + }) : assert(enabledCallback != null),
  478 + assert(onStartPopGesture != null),
  479 + assert(child != null),
  480 + super(key: key);
  481 +
  482 + final Widget child;
  483 +
  484 + final ValueGetter<bool> enabledCallback;
  485 +
  486 + final ValueGetter<_CupertinoBackGestureController<T>> onStartPopGesture;
  487 +
  488 + @override
  489 + _CupertinoBackGestureDetectorState<T> createState() =>
  490 + _CupertinoBackGestureDetectorState<T>();
  491 +}
  492 +
  493 +class _CupertinoBackGestureDetectorState<T>
  494 + extends State<_CupertinoBackGestureDetector<T>> {
  495 + _CupertinoBackGestureController<T> _backGestureController;
  496 +
  497 + HorizontalDragGestureRecognizer _recognizer;
  498 +
  499 + @override
  500 + void initState() {
  501 + super.initState();
  502 + _recognizer = HorizontalDragGestureRecognizer(debugOwner: this)
  503 + ..onStart = _handleDragStart
  504 + ..onUpdate = _handleDragUpdate
  505 + ..onEnd = _handleDragEnd
  506 + ..onCancel = _handleDragCancel;
  507 + }
  508 +
  509 + @override
  510 + void dispose() {
  511 + _recognizer.dispose();
  512 + super.dispose();
  513 + }
  514 +
  515 + void _handleDragStart(DragStartDetails details) {
  516 + assert(mounted);
  517 + assert(_backGestureController == null);
  518 + _backGestureController = widget.onStartPopGesture();
  519 + }
  520 +
  521 + void _handleDragUpdate(DragUpdateDetails details) {
  522 + assert(mounted);
  523 + assert(_backGestureController != null);
  524 + _backGestureController.dragUpdate(
  525 + _convertToLogical(details.primaryDelta / context.size.width));
  526 + }
  527 +
  528 + void _handleDragEnd(DragEndDetails details) {
  529 + assert(mounted);
  530 + assert(_backGestureController != null);
  531 + _backGestureController.dragEnd(_convertToLogical(
  532 + details.velocity.pixelsPerSecond.dx / context.size.width));
  533 + _backGestureController = null;
  534 + }
  535 +
  536 + void _handleDragCancel() {
  537 + assert(mounted);
  538 + // This can be called even if start is not called, paired with the "down" event
  539 + // that we don't consider here.
  540 + _backGestureController?.dragEnd(0.0);
  541 + _backGestureController = null;
  542 + }
  543 +
  544 + void _handlePointerDown(PointerDownEvent event) {
  545 + if (widget.enabledCallback()) _recognizer.addPointer(event);
  546 + }
  547 +
  548 + double _convertToLogical(double value) {
  549 + switch (Directionality.of(context)) {
  550 + case TextDirection.rtl:
  551 + return -value;
  552 + case TextDirection.ltr:
  553 + return value;
  554 + }
  555 + return null;
  556 + }
  557 +
  558 + @override
  559 + Widget build(BuildContext context) {
  560 + assert(debugCheckHasDirectionality(context));
  561 + // For devices with notches, the drag area needs to be larger on the side
  562 + // that has the notch.
  563 + double dragAreaWidth = Directionality.of(context) == TextDirection.ltr
  564 + ? MediaQuery.of(context).padding.left
  565 + : MediaQuery.of(context).padding.right;
  566 + dragAreaWidth = max(dragAreaWidth, _kBackGestureWidth);
  567 + return Stack(
  568 + fit: StackFit.passthrough,
  569 + children: <Widget>[
  570 + widget.child,
  571 + PositionedDirectional(
  572 + start: 0.0,
  573 + width: dragAreaWidth,
  574 + top: 0.0,
  575 + bottom: 0.0,
  576 + child: Listener(
  577 + onPointerDown: _handlePointerDown,
  578 + behavior: HitTestBehavior.translucent,
  579 + ),
  580 + ),
  581 + ],
  582 + );
  583 + }
  584 +}
  585 +
  586 +class _CupertinoBackGestureController<T> {
  587 + /// Creates a controller for an iOS-style back gesture.
  588 + ///
  589 + /// The [navigator] and [controller] arguments must not be null.
  590 + _CupertinoBackGestureController({
  591 + @required this.navigator,
  592 + @required this.controller,
  593 + }) : assert(navigator != null),
  594 + assert(controller != null) {
  595 + navigator.didStartUserGesture();
  596 + }
  597 +
  598 + final AnimationController controller;
  599 + final NavigatorState navigator;
  600 +
  601 + /// The drag gesture has changed by [fractionalDelta]. The total range of the
  602 + /// drag should be 0.0 to 1.0.
  603 + void dragUpdate(double delta) {
  604 + controller.value -= delta;
  605 + }
  606 +
  607 + /// The drag gesture has ended with a horizontal motion of
  608 + /// [fractionalVelocity] as a fraction of screen width per second.
  609 + void dragEnd(double velocity) {
  610 + // Fling in the appropriate direction.
  611 + // AnimationController.fling is guaranteed to
  612 + // take at least one frame.
  613 + //
  614 + // This curve has been determined through rigorously eyeballing native iOS
  615 + // animations.
  616 + const Curve animationCurve = Curves.fastLinearToSlowEaseIn;
  617 + bool animateForward;
  618 +
  619 + // If the user releases the page before mid screen with sufficient velocity,
  620 + // or after mid screen, we should animate the page out. Otherwise, the page
  621 + // should be animated back in.
  622 + if (velocity.abs() >= _kMinFlingVelocity)
  623 + animateForward = velocity <= 0;
  624 + else
  625 + animateForward = controller.value > 0.5;
  626 +
  627 + if (animateForward) {
  628 + // The closer the panel is to dismissing, the shorter the animation is.
  629 + // We want to cap the animation time, but we want to use a linear curve
  630 + // to determine it.
  631 + final int droppedPageForwardAnimationTime = min(
  632 + lerpDouble(
  633 + _kMaxDroppedSwipePageForwardAnimationTime, 0, controller.value)
  634 + .floor(),
  635 + _kMaxPageBackAnimationTime,
  636 + );
  637 + controller.animateTo(1.0,
  638 + duration: Duration(milliseconds: droppedPageForwardAnimationTime),
  639 + curve: animationCurve);
  640 + } else {
  641 + // This route is destined to pop at this point. Reuse navigator's pop.
  642 + navigator.pop();
  643 +
  644 + // The popping may have finished inline if already at the target destination.
  645 + if (controller.isAnimating) {
  646 + // Otherwise, use a custom popping animation duration and curve.
  647 + final int droppedPageBackAnimationTime = lerpDouble(
  648 + 0, _kMaxDroppedSwipePageForwardAnimationTime, controller.value)
  649 + .floor();
  650 + controller.animateBack(0.0,
  651 + duration: Duration(milliseconds: droppedPageBackAnimationTime),
  652 + curve: animationCurve);
  653 + }
  654 + }
  655 +
  656 + if (controller.isAnimating) {
  657 + // Keep the userGestureInProgress in true state so we don't change the
  658 + // curve of the page transition mid-flight since CupertinoPageTransition
  659 + // depends on userGestureInProgress.
  660 + AnimationStatusListener animationStatusCallback;
  661 + animationStatusCallback = (AnimationStatus status) {
  662 + navigator.didStopUserGesture();
  663 + controller.removeStatusListener(animationStatusCallback);
  664 + };
  665 + controller.addStatusListener(animationStatusCallback);
  666 + } else {
  667 + navigator.didStopUserGesture();
  668 + }
  669 + }
  670 +}
  1 +import 'dart:io';
  2 +
1 import 'package:flutter/material.dart'; 3 import 'package:flutter/material.dart';
2 import 'package:flutter/scheduler.dart'; 4 import 'package:flutter/scheduler.dart';
3 import 'backdrop_blur.dart'; 5 import 'backdrop_blur.dart';
4 import 'bottomsheet.dart'; 6 import 'bottomsheet.dart';
5 import 'dialog.dart'; 7 import 'dialog.dart';
  8 +import 'getroute_cupertino.dart';
6 import 'snack.dart'; 9 import 'snack.dart';
7 import 'getroute.dart'; 10 import 'getroute.dart';
  11 +import 'transitions_type.dart';
8 import 'transparent_route.dart'; 12 import 'transparent_route.dart';
9 13
10 class Get { 14 class Get {
@@ -46,15 +50,22 @@ class Get { @@ -46,15 +50,22 @@ class Get {
46 /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior 50 /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior
47 /// of rebuilding every app after a route, use rebuildRoutes = true as the parameter. 51 /// of rebuilding every app after a route, use rebuildRoutes = true as the parameter.
48 static to(Widget page, 52 static to(Widget page,
49 - {bool rebuildRoutes = false,  
50 - Transition transition = Transition.fade, 53 + {bool rebuildRoutes,
  54 + Transition transition,
51 Duration duration = const Duration(milliseconds: 400)}) { 55 Duration duration = const Duration(milliseconds: 400)}) {
52 // if (key.currentState.mounted) // add this if appear problems on future with route navigate 56 // if (key.currentState.mounted) // add this if appear problems on future with route navigate
53 // when widget don't mounted 57 // when widget don't mounted
54 - return key.currentState.push(GetRoute(  
55 - opaque: rebuildRoutes, 58 +
  59 + return Platform.isIOS
  60 + ? key.currentState.push(GetCupertino(
  61 + opaque: rebuildRoutes ?? true,
56 page: page, 62 page: page,
57 - transition: transition, 63 + transition: transition ?? Transition.cupertino,
  64 + duration: duration))
  65 + : key.currentState.push(GetRoute(
  66 + opaque: rebuildRoutes ?? false,
  67 + page: page,
  68 + transition: transition ?? Transition.fade,
58 duration: duration)); 69 duration: duration));
59 } 70 }
60 71
@@ -357,4 +368,16 @@ class Get { @@ -357,4 +368,16 @@ class Get {
357 ..show(); 368 ..show();
358 }); 369 });
359 } 370 }
  371 +
  372 + static iconColor() {
  373 + return Theme.of(key.currentContext).iconTheme.color;
  374 + }
  375 +
  376 + static height() {
  377 + return MediaQuery.of(key.currentContext).size.height;
  378 + }
  379 +
  380 + static width() {
  381 + return MediaQuery.of(key.currentContext).size.width;
  382 + }
360 } 383 }
  1 +enum Transition {
  2 + fade,
  3 + rightToLeft,
  4 + leftToRight,
  5 + upToDown,
  6 + downToUp,
  7 + scale,
  8 + rotate,
  9 + size,
  10 + rightToLeftWithFade,
  11 + leftToRightWithFade,
  12 + cupertino
  13 +}
1 name: get 1 name: get
2 description: A consistent navigation library that lets you navigate between screens, open dialogs, and display snackbars easily with no context. 2 description: A consistent navigation library that lets you navigate between screens, open dialogs, and display snackbars easily with no context.
3 -version: 1.10.5 3 +version: 1.11.1
4 homepage: https://github.com/jonataslaw/get 4 homepage: https://github.com/jonataslaw/get
5 5
6 environment: 6 environment: