default_route.dart
35.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
import 'dart:math';
import 'dart:ui' show lerpDouble;
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:get/src/get_main.dart';
import 'package:get/src/instance/get_instance.dart';
import 'package:get/src/platform/platform.dart';
import 'bindings_interface.dart';
import 'custom_transition.dart';
import 'transitions_filter.dart';
import 'transitions_type.dart';
class GetPageRoute<T> extends PageRouteBuilder<T> {
//final TransitionComponent transitionComponent;
final Duration duration;
final bool popGesture;
final Transition transition;
final Curve curve;
final GetPageBuilder page;
final CustomTransition customTransition;
final Bindings binding;
final Map<String, String> parameter;
final List<Bindings> bindings;
GetPageRoute({
// this.transitionComponent,
RouteSettings settings,
this.duration,
this.transition = Transition.native,
this.binding,
@required this.page,
this.bindings,
this.opaque = true,
this.parameter,
this.fullscreenDialog = false,
this.curve,
this.popGesture,
this.customTransition,
}) : super(
pageBuilder: (context, anim1, anim2) {
if (binding != null) {
binding.dependencies();
}
if (bindings != null) {
for (Bindings element in bindings) {
element.dependencies();
}
}
GetConfig.currentRoute = settings.name;
return page();
},
settings: settings,
);
@override
final bool opaque;
@override
final bool fullscreenDialog;
@override
Widget buildTransitions(BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation, Widget child) {
if (this.customTransition != null) {
return this.customTransition.buildTransition(
context,
animation,
secondaryAnimation,
popGesture ?? Get.defaultPopGesture
? _CupertinoBackGestureDetector<T>(
enabledCallback: () => _isPopGestureEnabled<T>(this),
onStartPopGesture: () => _startPopGesture<T>(this),
child: child)
: child);
}
final curvedAnimation = CurvedAnimation(
parent: animation,
curve: this.curve ?? Curves.linear,
);
if (transition == null) {
if (Get.customTransition != null) {
return Get.customTransition.buildTransition(
context,
animation,
secondaryAnimation,
popGesture ?? Get.defaultPopGesture
? _CupertinoBackGestureDetector<T>(
enabledCallback: () => _isPopGestureEnabled<T>(this),
onStartPopGesture: () => _startPopGesture<T>(this),
child: child)
: child);
}
if (Get.defaultTransition != null) {
return TransitionFilter.newTransitionComponent(Get.defaultTransition)
.buildChildWithTransition(
context,
curvedAnimation,
secondaryAnimation,
popGesture ?? Get.defaultPopGesture
? _CupertinoBackGestureDetector<T>(
enabledCallback: () => _isPopGestureEnabled<T>(this),
onStartPopGesture: () => _startPopGesture<T>(this),
child: child)
: child);
}
return Theme.of(context).pageTransitionsTheme.buildTransitions(
this,
context,
animation,
secondaryAnimation,
GetPlatform.isIOS
? _CupertinoBackGestureDetector<T>(
enabledCallback: () => _isPopGestureEnabled<T>(this),
onStartPopGesture: () => _startPopGesture<T>(this),
child: child)
: child);
}
return TransitionFilter.newTransitionComponent(transition)
.buildChildWithTransition(
context,
curvedAnimation,
secondaryAnimation,
popGesture ?? Get.defaultPopGesture
? _CupertinoBackGestureDetector<T>(
enabledCallback: () => _isPopGestureEnabled<T>(this),
onStartPopGesture: () => _startPopGesture<T>(this),
child: child)
: child);
}
@override
Duration get transitionDuration =>
this.duration ?? Duration(milliseconds: 300);
static bool _isPopGestureEnabled<T>(PageRoute<T> route) {
if (route.isFirst) return false;
if (route.willHandlePopInternally) return false;
if (route.hasScopedWillPopCallback) return false;
if (route.fullscreenDialog) return false;
if (route.animation.status != AnimationStatus.completed) return false;
if (route.secondaryAnimation.status != AnimationStatus.dismissed)
return false;
if (isPopGestureInProgress(route)) return false;
return true;
}
static _CupertinoBackGestureController<T> _startPopGesture<T>(
PageRoute<T> route) {
assert(_isPopGestureEnabled(route));
return _CupertinoBackGestureController<T>(
navigator: route.navigator,
controller: route.controller,
);
}
static bool isPopGestureInProgress(PageRoute<dynamic> route) {
return route.navigator.userGestureInProgress;
}
bool get popGestureInProgress => isPopGestureInProgress(this);
}
const double _kBackGestureWidth = 20.0;
const double _kMinFlingVelocity = 1.0;
const int _kMaxDroppedSwipePageForwardAnimationTime = 800; // Milliseconds.
// The maximum time for a page to get reset to it's original position if the
// user releases a page mid swipe.
const int _kMaxPageBackAnimationTime = 300;
class _CupertinoBackGestureDetector<T> extends StatefulWidget {
const _CupertinoBackGestureDetector({
Key key,
@required this.enabledCallback,
@required this.onStartPopGesture,
@required this.child,
}) : assert(enabledCallback != null),
assert(onStartPopGesture != null),
assert(child != null),
super(key: key);
final Widget child;
final ValueGetter<bool> enabledCallback;
final ValueGetter<_CupertinoBackGestureController<T>> onStartPopGesture;
@override
_CupertinoBackGestureDetectorState<T> createState() =>
_CupertinoBackGestureDetectorState<T>();
}
class _CupertinoBackGestureDetectorState<T>
extends State<_CupertinoBackGestureDetector<T>> {
_CupertinoBackGestureController<T> _backGestureController;
HorizontalDragGestureRecognizer _recognizer;
@override
void initState() {
super.initState();
_recognizer = HorizontalDragGestureRecognizer(debugOwner: this)
..onStart = _handleDragStart
..onUpdate = _handleDragUpdate
..onEnd = _handleDragEnd
..onCancel = _handleDragCancel;
}
@override
void dispose() {
_recognizer.dispose();
super.dispose();
}
void _handleDragStart(DragStartDetails details) {
assert(mounted);
assert(_backGestureController == null);
_backGestureController = widget.onStartPopGesture();
}
void _handleDragUpdate(DragUpdateDetails details) {
assert(mounted);
assert(_backGestureController != null);
_backGestureController.dragUpdate(
_convertToLogical(details.primaryDelta / context.size.width));
}
void _handleDragEnd(DragEndDetails details) {
assert(mounted);
assert(_backGestureController != null);
_backGestureController.dragEnd(_convertToLogical(
details.velocity.pixelsPerSecond.dx / context.size.width));
_backGestureController = null;
}
void _handleDragCancel() {
assert(mounted);
// This can be called even if start is not called, paired with the "down" event
// that we don't consider here.
_backGestureController?.dragEnd(0.0);
_backGestureController = null;
}
void _handlePointerDown(PointerDownEvent event) {
if (widget.enabledCallback()) _recognizer.addPointer(event);
}
double _convertToLogical(double value) {
switch (Directionality.of(context)) {
case TextDirection.rtl:
return -value;
case TextDirection.ltr:
return value;
}
return null;
}
@override
Widget build(BuildContext context) {
assert(debugCheckHasDirectionality(context));
// For devices with notches, the drag area needs to be larger on the side
// that has the notch.
double dragAreaWidth = Directionality.of(context) == TextDirection.ltr
? MediaQuery.of(context).padding.left
: MediaQuery.of(context).padding.right;
dragAreaWidth = max(dragAreaWidth, _kBackGestureWidth);
return Stack(
fit: StackFit.passthrough,
children: <Widget>[
widget.child,
PositionedDirectional(
start: 0.0,
width: dragAreaWidth,
top: 0.0,
bottom: 0.0,
child: Listener(
onPointerDown: _handlePointerDown,
behavior: HitTestBehavior.translucent,
),
),
],
);
}
}
class _CupertinoBackGestureController<T> {
/// Creates a controller for an iOS-style back gesture.
///
/// The [navigator] and [controller] arguments must not be null.
_CupertinoBackGestureController({
@required this.navigator,
@required this.controller,
}) : assert(navigator != null),
assert(controller != null) {
navigator.didStartUserGesture();
}
final AnimationController controller;
final NavigatorState navigator;
/// The drag gesture has changed by [fractionalDelta]. The total range of the
/// drag should be 0.0 to 1.0.
void dragUpdate(double delta) {
controller.value -= delta;
}
/// The drag gesture has ended with a horizontal motion of
/// [fractionalVelocity] as a fraction of screen width per second.
void dragEnd(double velocity) {
// Fling in the appropriate direction.
// AnimationController.fling is guaranteed to
// take at least one frame.
//
// This curve has been determined through rigorously eyeballing native iOS
// animations.
const Curve animationCurve = Curves.fastLinearToSlowEaseIn;
bool animateForward;
// If the user releases the page before mid screen with sufficient velocity,
// or after mid screen, we should animate the page out. Otherwise, the page
// should be animated back in.
if (velocity.abs() >= _kMinFlingVelocity) {
animateForward = velocity <= 0;
} else {
animateForward = controller.value > 0.5;
}
if (animateForward) {
// The closer the panel is to dismissing, the shorter the animation is.
// We want to cap the animation time, but we want to use a linear curve
// to determine it.
final int droppedPageForwardAnimationTime = min(
lerpDouble(
_kMaxDroppedSwipePageForwardAnimationTime, 0, controller.value)
.floor(),
_kMaxPageBackAnimationTime,
);
controller.animateTo(1.0,
duration: Duration(milliseconds: droppedPageForwardAnimationTime),
curve: animationCurve);
} else {
// This route is destined to pop at this point. Reuse navigator's pop.
navigator.pop();
// The popping may have finished inline if already at the target destination.
if (controller.isAnimating) {
// Otherwise, use a custom popping animation duration and curve.
final int droppedPageBackAnimationTime = lerpDouble(
0, _kMaxDroppedSwipePageForwardAnimationTime, controller.value)
.floor();
controller.animateBack(0.0,
duration: Duration(milliseconds: droppedPageBackAnimationTime),
curve: animationCurve);
}
}
if (controller.isAnimating) {
// Keep the userGestureInProgress in true state so we don't change the
// curve of the page transition mid-flight since CupertinoPageTransition
// depends on userGestureInProgress.
AnimationStatusListener animationStatusCallback;
animationStatusCallback = (AnimationStatus status) {
navigator.didStopUserGesture();
controller.removeStatusListener(animationStatusCallback);
};
controller.addStatusListener(animationStatusCallback);
} else {
navigator.didStopUserGesture();
}
}
}
// import 'package:flutter/cupertino.dart';
// import 'package:flutter/foundation.dart';
// import 'package:flutter/gestures.dart';
// import 'package:flutter/material.dart';
// import 'package:get/src/get_main.dart';
// import 'package:get/src/routes/bindings_interface.dart';
// import '../platform/platform.dart';
// import 'transitions_type.dart';
// const double _kBackGestureWidth = 20.0;
// const double _kMinFlingVelocity = 1.0;
// const int _kMaxDroppedSwipePageForwardAnimationTime = 800; // Milliseconds.
// // The maximum time for a page to get reset to it's original position if the
// // user releases a page mid swipe.
// const int _kMaxPageBackAnimationTime = 300;
// class GetPageRoute<T> extends PageRoute<T> {
// /// The [builder], [maintainState], and [fullscreenDialog] arguments must not
// /// be null.
// GetPageRoute({
// @required this.page,
// this.title,
// RouteSettings settings,
// this.maintainState = true,
// this.curve = Curves.linear,
// this.alignment,
// this.parameter,
// this.binding,
// this.route,
// this.bindings,
// this.customBuildPageTransitions,
// this.opaque = true,
// this.transitionDuration = const Duration(milliseconds: 400),
// this.popGesture,
// this.transition,
// // this.duration = const Duration(milliseconds: 400),
// bool fullscreenDialog = false,
// }) : // assert(page != null),
// assert(maintainState != null),
// assert(fullscreenDialog != null),
// // assert(opaque),
// super(settings: settings, fullscreenDialog: fullscreenDialog) {
// /// prebuild dependencies
// if (binding != null) {
// binding.dependencies();
// }
// if (bindings != null) {
// bindings.forEach((element) => element.dependencies());
// }
// }
// /// Builds the primary contents of the route.
// final Widget page;
// final GetPageBuilder route;
// final Widget customBuildPageTransitions;
// final bool popGesture;
// final Bindings binding;
// final List<Bindings> bindings;
// // final Duration duration;
// final Map<String, String> parameter;
// final String title;
// final Transition transition;
// final Curve curve;
// final Alignment alignment;
// ValueNotifier<String> _previousTitle;
// /// The title string of the previous [GetRoute].
// ///
// /// The [ValueListenable]'s value is readable after the route is installed
// /// onto a [Navigator]. The [ValueListenable] will also notify its listeners
// /// if the value changes (such as by replacing the previous route).
// ///
// /// The [ValueListenable] itself will be null before the route is installed.
// /// Its content value will be null if the previous route has no title or
// /// is not a [GetRoute].
// ///
// /// See also:
// ///
// /// * [ValueListenableBuilder], which can be used to listen and rebuild
// /// widgets based on a ValueListenable.
// ValueListenable<String> get previousTitle {
// assert(
// _previousTitle != null,
// 'Cannot read the previousTitle for a route that has not yet been installed',
// );
// return _previousTitle;
// }
// @override
// void didChangePrevious(Route<dynamic> previousRoute) {
// final String previousTitleString =
// previousRoute is GetPageRoute ? previousRoute.title : null;
// if (_previousTitle == null) {
// _previousTitle = ValueNotifier<String>(previousTitleString);
// } else {
// _previousTitle.value = previousTitleString;
// }
// super.didChangePrevious(previousRoute);
// }
// @override
// final bool maintainState;
// /// Allows you to set opaque to false to prevent route reconstruction.
// @override
// final bool opaque;
// @override
// final Duration transitionDuration;
// @override
// Color get barrierColor => null; //Color(0x00FFFFFF);
// @override
// String get barrierLabel => null;
// @override
// bool canTransitionTo(TransitionRoute<dynamic> nextRoute) {
// // Don't perform outgoing animation if the next route is a fullscreen dialog.
// return nextRoute is GetPageRoute && !nextRoute.fullscreenDialog;
// }
// /// True if an iOS-style back swipe pop gesture is currently underway for [route].
// ///
// /// This just check the route's [NavigatorState.userGestureInProgress].
// ///
// /// See also:
// ///
// /// * [popGestureEnabled], which returns true if a user-triggered pop gesture
// /// would be allowed.
// static bool isPopGestureInProgress(PageRoute<dynamic> route) {
// return route.navigator.userGestureInProgress;
// }
// /// True if an iOS-style back swipe pop gesture is currently underway for this route.
// ///
// /// See also:
// ///
// /// * [isPopGestureInProgress], which returns true if a Cupertino pop gesture
// /// is currently underway for specific route.
// /// * [popGestureEnabled], which returns true if a user-triggered pop gesture
// /// would be allowed.
// bool get popGestureInProgress => isPopGestureInProgress(this);
// /// Whether a pop gesture can be started by the user.
// ///
// /// Returns true if the user can edge-swipe to a previous route.
// ///
// /// Returns false once [isPopGestureInProgress] is true, but
// /// [isPopGestureInProgress] can only become true if [popGestureEnabled] was
// /// true first.
// ///
// /// This should only be used between frames, not during build.
// bool get popGestureEnabled => _isPopGestureEnabled(this);
// static bool _isPopGestureEnabled<T>(PageRoute<T> route) {
// // If there's nothing to go back to, then obviously we don't support
// // the back gesture.
// if (route.isFirst) return false;
// // If the route wouldn't actually pop if we popped it, then the gesture
// // would be really confusing (or would skip internal routes), so disallow it.
// if (route.willHandlePopInternally) return false;
// // If attempts to dismiss this route might be vetoed such as in a page
// // with forms, then do not allow the user to dismiss the route with a swipe.
// if (route.hasScopedWillPopCallback) return false;
// // Fullscreen dialogs aren't dismissible by back swipe.
// if (route.fullscreenDialog) return false;
// // If we're in an animation already, we cannot be manually swiped.
// if (route.animation.status != AnimationStatus.completed) return false;
// // If we're being popped into, we also cannot be swiped until the pop above
// // it completes. This translates to our secondary animation being
// // dismissed.
// if (route.secondaryAnimation.status != AnimationStatus.dismissed)
// return false;
// // If we're in a gesture already, we cannot start another.
// if (isPopGestureInProgress(route)) return false;
// // Looks like a back gesture would be welcome!
// return true;
// }
// @override
// Widget buildPage(BuildContext context, Animation<double> animation,
// Animation<double> secondaryAnimation) {
// final Widget result = Semantics(
// scopesRoute: true,
// explicitChildNodes: true,
// child: (route == null ? page : route()),
// );
// assert(() {
// if (route == null && page == null) {
// throw FlutterError.fromParts(<DiagnosticsNode>[
// ErrorSummary(
// 'The builder for route "${settings.name}" returned null.'),
// ErrorDescription('Route builders must never return null.'),
// ]);
// }
// return true;
// }());
// return result;
// }
// // Called by _CupertinoBackGestureDetector when a pop ("back") drag start
// // gesture is detected. The returned controller handles all of the subsequent
// // drag events.
// static _CupertinoBackGestureController<T> _startPopGesture<T>(
// PageRoute<T> route) {
// assert(_isPopGestureEnabled(route));
// return _CupertinoBackGestureController<T>(
// navigator: route.navigator,
// controller: route.controller, // protected access
// );
// }
// /// Returns a [CupertinoFullscreenDialogTransition] if [route] is a full
// /// screen dialog, otherwise a [CupertinoPageTransition] is returned.
// ///
// /// Used by [GetRoute.buildTransitions].
// ///
// /// This method can be applied to any [PageRoute], not just
// /// [GetRoute]. It's typically used to provide a Cupertino style
// /// horizontal transition for material widgets when the target platform
// /// is [TargetPlatform.iOS].
// ///
// /// See also:
// ///
// /// * [CupertinoPageTransitionsBuilder], which uses this method to define a
// /// [PageTransitionsBuilder] for the [PageTransitionsTheme].
// Widget buildPageTransitions<T>(
// PageRoute<T> route,
// BuildContext context,
// bool popGesture,
// Animation<double> animation,
// Animation<double> secondaryAnimation,
// Widget child,
// Transition tr,
// Curve curve,
// Alignment alignment,
// ) {
// Transition transition = (tr ?? Get.defaultTransition);
// if (route.fullscreenDialog) {
// final bool linearTransition = isPopGestureInProgress(route);
// return CupertinoFullscreenDialogTransition(
// primaryRouteAnimation: animation,
// secondaryRouteAnimation: secondaryAnimation,
// child: child,
// linearTransition: linearTransition,
// );
// } else {
// switch (transition) {
// case Transition.fade:
// final PageTransitionsBuilder matchingBuilder =
// FadeUpwardsPageTransitionsBuilder();
// return matchingBuilder.buildTransitions<T>(
// route,
// context,
// animation,
// secondaryAnimation,
// popGesture
// ? _CupertinoBackGestureDetector<T>(
// enabledCallback: () => _isPopGestureEnabled<T>(route),
// onStartPopGesture: () => _startPopGesture<T>(route),
// child: child)
// : child);
// break;
// case Transition.rightToLeft:
// return SlideTransition(
// transformHitTests: false,
// position: new Tween<Offset>(
// begin: const Offset(1.0, 0.0),
// end: Offset.zero,
// ).animate(animation),
// child: new SlideTransition(
// position: new Tween<Offset>(
// begin: Offset.zero,
// end: const Offset(-1.0, 0.0),
// ).animate(secondaryAnimation),
// child: popGesture
// ? _CupertinoBackGestureDetector<T>(
// enabledCallback: () => _isPopGestureEnabled<T>(route),
// onStartPopGesture: () => _startPopGesture<T>(route),
// child: child)
// : child),
// );
// break;
// case Transition.leftToRight:
// return SlideTransition(
// transformHitTests: false,
// position: Tween<Offset>(
// begin: const Offset(-1.0, 0.0),
// end: Offset.zero,
// ).animate(animation),
// child: new SlideTransition(
// position: new Tween<Offset>(
// begin: Offset.zero,
// end: const Offset(1.0, 0.0),
// ).animate(secondaryAnimation),
// child: popGesture
// ? _CupertinoBackGestureDetector<T>(
// enabledCallback: () => _isPopGestureEnabled<T>(route),
// onStartPopGesture: () => _startPopGesture<T>(route),
// child: child)
// : child),
// );
// break;
// case Transition.upToDown:
// return SlideTransition(
// transformHitTests: false,
// position: Tween<Offset>(
// begin: const Offset(0.0, -1.0),
// end: Offset.zero,
// ).animate(animation),
// child: new SlideTransition(
// position: new Tween<Offset>(
// begin: Offset.zero,
// end: const Offset(0.0, 1.0),
// ).animate(secondaryAnimation),
// child: popGesture
// ? _CupertinoBackGestureDetector<T>(
// enabledCallback: () => _isPopGestureEnabled<T>(route),
// onStartPopGesture: () => _startPopGesture<T>(route),
// child: child)
// : child),
// );
// break;
// case Transition.downToUp:
// return SlideTransition(
// transformHitTests: false,
// position: Tween<Offset>(
// begin: const Offset(0.0, 1.0),
// end: Offset.zero,
// ).animate(animation),
// child: new SlideTransition(
// position: new Tween<Offset>(
// begin: Offset.zero,
// end: const Offset(0.0, -1.0),
// ).animate(secondaryAnimation),
// child: popGesture
// ? _CupertinoBackGestureDetector<T>(
// enabledCallback: () => _isPopGestureEnabled<T>(route),
// onStartPopGesture: () => _startPopGesture<T>(route),
// child: child)
// : child),
// );
// break;
// case Transition.rightToLeftWithFade:
// return SlideTransition(
// position: Tween<Offset>(
// begin: const Offset(1.0, 0.0),
// end: Offset.zero,
// ).animate(animation),
// child: FadeTransition(
// opacity: animation,
// child: SlideTransition(
// position: Tween<Offset>(
// begin: Offset.zero,
// end: const Offset(-1.0, 0.0),
// ).animate(secondaryAnimation),
// child: popGesture
// ? _CupertinoBackGestureDetector<T>(
// enabledCallback: () => _isPopGestureEnabled<T>(route),
// onStartPopGesture: () => _startPopGesture<T>(route),
// child: child)
// : child),
// ),
// );
// break;
// case Transition.leftToRightWithFade:
// return SlideTransition(
// position: Tween<Offset>(
// begin: const Offset(-1.0, 0.0),
// end: Offset.zero,
// ).animate(animation),
// child: FadeTransition(
// opacity: animation,
// child: SlideTransition(
// position: Tween<Offset>(
// begin: Offset.zero,
// end: const Offset(1.0, 0.0),
// ).animate(secondaryAnimation),
// child: popGesture
// ? _CupertinoBackGestureDetector<T>(
// enabledCallback: () => _isPopGestureEnabled<T>(route),
// onStartPopGesture: () => _startPopGesture<T>(route),
// child: child)
// : child),
// ),
// );
// break;
// default:
// return CupertinoPageTransition(
// primaryRouteAnimation: animation,
// secondaryRouteAnimation: secondaryAnimation,
// // Check if the route has an animation that's currently participating
// // in a back swipe gesture.
// //
// // In the middle of a back gesture drag, let the transition be linear to
// // match finger motions.
// linearTransition: isPopGestureInProgress(route),
// child: popGesture
// ? _CupertinoBackGestureDetector<T>(
// enabledCallback: () => _isPopGestureEnabled<T>(route),
// onStartPopGesture: () => _startPopGesture<T>(route),
// child: child)
// : child,
// );
// }
// }
// }
// @override
// Widget buildTransitions(BuildContext context, Animation<double> animation,
// Animation<double> secondaryAnimation, Widget child) {
// if (customBuildPageTransitions != null) {
// return customBuildPageTransitions;
// } else {
// return buildPageTransitions<T>(
// this,
// context,
// popGesture ?? GetPlatform.isIOS,
// animation,
// secondaryAnimation,
// child,
// transition,
// curve,
// alignment);
// }
// }
// @override
// String get debugLabel => '${super.debugLabel}(${settings.name})';
// }
// class _CupertinoBackGestureDetector<T> extends StatefulWidget {
// const _CupertinoBackGestureDetector({
// Key key,
// @required this.enabledCallback,
// @required this.onStartPopGesture,
// @required this.child,
// }) : assert(enabledCallback != null),
// assert(onStartPopGesture != null),
// assert(child != null),
// super(key: key);
// final Widget child;
// final ValueGetter<bool> enabledCallback;
// final ValueGetter<_CupertinoBackGestureController<T>> onStartPopGesture;
// @override
// _CupertinoBackGestureDetectorState<T> createState() =>
// _CupertinoBackGestureDetectorState<T>();
// }
// class _CupertinoBackGestureDetectorState<T>
// extends State<_CupertinoBackGestureDetector<T>> {
// _CupertinoBackGestureController<T> _backGestureController;
// HorizontalDragGestureRecognizer _recognizer;
// @override
// void initState() {
// super.initState();
// _recognizer = HorizontalDragGestureRecognizer(debugOwner: this)
// ..onStart = _handleDragStart
// ..onUpdate = _handleDragUpdate
// ..onEnd = _handleDragEnd
// ..onCancel = _handleDragCancel;
// }
// @override
// void dispose() {
// _recognizer.dispose();
// super.dispose();
// }
// void _handleDragStart(DragStartDetails details) {
// assert(mounted);
// assert(_backGestureController == null);
// _backGestureController = widget.onStartPopGesture();
// }
// void _handleDragUpdate(DragUpdateDetails details) {
// assert(mounted);
// assert(_backGestureController != null);
// _backGestureController.dragUpdate(
// _convertToLogical(details.primaryDelta / context.size.width));
// }
// void _handleDragEnd(DragEndDetails details) {
// assert(mounted);
// assert(_backGestureController != null);
// _backGestureController.dragEnd(_convertToLogical(
// details.velocity.pixelsPerSecond.dx / context.size.width));
// _backGestureController = null;
// }
// void _handleDragCancel() {
// assert(mounted);
// // This can be called even if start is not called, paired with the "down" event
// // that we don't consider here.
// _backGestureController?.dragEnd(0.0);
// _backGestureController = null;
// }
// void _handlePointerDown(PointerDownEvent event) {
// if (widget.enabledCallback()) _recognizer.addPointer(event);
// }
// double _convertToLogical(double value) {
// switch (Directionality.of(context)) {
// case TextDirection.rtl:
// return -value;
// case TextDirection.ltr:
// return value;
// }
// return null;
// }
// @override
// Widget build(BuildContext context) {
// assert(debugCheckHasDirectionality(context));
// // For devices with notches, the drag area needs to be larger on the side
// // that has the notch.
// double dragAreaWidth = Directionality.of(context) == TextDirection.ltr
// ? MediaQuery.of(context).padding.left
// : MediaQuery.of(context).padding.right;
// dragAreaWidth = max(dragAreaWidth, _kBackGestureWidth);
// return Stack(
// fit: StackFit.passthrough,
// children: <Widget>[
// widget.child,
// PositionedDirectional(
// start: 0.0,
// width: dragAreaWidth,
// top: 0.0,
// bottom: 0.0,
// child: Listener(
// onPointerDown: _handlePointerDown,
// behavior: HitTestBehavior.translucent,
// ),
// ),
// ],
// );
// }
// }
// class _CupertinoBackGestureController<T> {
// /// Creates a controller for an iOS-style back gesture.
// ///
// /// The [navigator] and [controller] arguments must not be null.
// _CupertinoBackGestureController({
// @required this.navigator,
// @required this.controller,
// }) : assert(navigator != null),
// assert(controller != null) {
// navigator.didStartUserGesture();
// }
// final AnimationController controller;
// final NavigatorState navigator;
// /// The drag gesture has changed by [fractionalDelta]. The total range of the
// /// drag should be 0.0 to 1.0.
// void dragUpdate(double delta) {
// controller.value -= delta;
// }
// /// The drag gesture has ended with a horizontal motion of
// /// [fractionalVelocity] as a fraction of screen width per second.
// void dragEnd(double velocity) {
// // Fling in the appropriate direction.
// // AnimationController.fling is guaranteed to
// // take at least one frame.
// //
// // This curve has been determined through rigorously eyeballing native iOS
// // animations.
// const Curve animationCurve = Curves.fastLinearToSlowEaseIn;
// bool animateForward;
// // If the user releases the page before mid screen with sufficient velocity,
// // or after mid screen, we should animate the page out. Otherwise, the page
// // should be animated back in.
// if (velocity.abs() >= _kMinFlingVelocity)
// animateForward = velocity <= 0;
// else
// animateForward = controller.value > 0.5;
// if (animateForward) {
// // The closer the panel is to dismissing, the shorter the animation is.
// // We want to cap the animation time, but we want to use a linear curve
// // to determine it.
// final int droppedPageForwardAnimationTime = min(
// lerpDouble(
// _kMaxDroppedSwipePageForwardAnimationTime, 0, controller.value)
// .floor(),
// _kMaxPageBackAnimationTime,
// );
// controller.animateTo(1.0,
// duration: Duration(milliseconds: droppedPageForwardAnimationTime),
// curve: animationCurve);
// } else {
// // This route is destined to pop at this point. Reuse navigator's pop.
// navigator.pop();
// // The popping may have finished inline if already at the target destination.
// if (controller.isAnimating) {
// // Otherwise, use a custom popping animation duration and curve.
// final int droppedPageBackAnimationTime = lerpDouble(
// 0, _kMaxDroppedSwipePageForwardAnimationTime, controller.value)
// .floor();
// controller.animateBack(0.0,
// duration: Duration(milliseconds: droppedPageBackAnimationTime),
// curve: animationCurve);
// }
// }
// if (controller.isAnimating) {
// // Keep the userGestureInProgress in true state so we don't change the
// // curve of the page transition mid-flight since CupertinoPageTransition
// // depends on userGestureInProgress.
// AnimationStatusListener animationStatusCallback;
// animationStatusCallback = (AnimationStatus status) {
// navigator.didStopUserGesture();
// controller.removeStatusListener(animationStatusCallback);
// };
// controller.addStatusListener(animationStatusCallback);
// } else {
// navigator.didStopUserGesture();
// }
// }
// }