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