Jonny Borges
Committed by GitHub

update to 3.2.2

## [3.2.2]
- Improve transitions and refactor route system
## [3.2.1]
- Prevent black blackground on cupertino fullscreenDialog
... ...
... ... @@ -62,7 +62,7 @@ class GetImpl implements GetService {
transition: transition ?? defaultTransition,
fullscreenDialog: fullscreenDialog,
binding: binding,
duration: duration ?? defaultDurationTransition));
transitionDuration: duration ?? defaultDurationTransition));
}
/// It replaces Navigator.pushNamed, but needs no context, and it doesn't have the Navigator.pushNamed
... ... @@ -195,7 +195,7 @@ class GetImpl implements GetService {
fullscreenDialog: fullscreenDialog,
popGesture: popGesture ?? defaultPopGesture,
transition: transition ?? defaultTransition,
duration: duration ?? defaultDurationTransition));
transitionDuration: duration ?? defaultDurationTransition));
}
/// It replaces Navigator.pushAndRemoveUntil, but needs no context
... ... @@ -221,7 +221,7 @@ class GetImpl implements GetService {
RouteSettings(name: '/${page.runtimeType}', arguments: arguments),
fullscreenDialog: fullscreenDialog,
transition: transition ?? defaultTransition,
duration: duration ?? defaultDurationTransition,
transitionDuration: duration ?? defaultDurationTransition,
),
predicate ?? route);
}
... ... @@ -583,7 +583,7 @@ class GetImpl implements GetService {
ParseRouteTree routeTree;
addPages(List<GetPage> getPages) {
void addPages(List<GetPage> getPages) {
if (getPages != null) {
if (routeTree == null) routeTree = ParseRouteTree();
getPages.forEach((element) {
... ... @@ -592,7 +592,7 @@ class GetImpl implements GetService {
}
}
addPage(GetPage getPage) {
void addPage(GetPage getPage) {
if (getPage != null) {
if (routeTree == null) routeTree = ParseRouteTree();
routeTree.addRoute(getPage);
... ... @@ -600,7 +600,7 @@ class GetImpl implements GetService {
}
/// change default config of Get
config(
void config(
{bool enableLog,
bool defaultPopGesture,
bool defaultOpaqueRoute,
... ... @@ -696,11 +696,11 @@ class GetImpl implements GetService {
Map<String, String> parameters = {};
setRouting(Routing rt) {
void setRouting(Routing rt) {
_routing = rt;
}
setSettings(RouteSettings settings) {
void setSettings(RouteSettings settings) {
settings = settings;
}
... ... @@ -708,10 +708,10 @@ class GetImpl implements GetService {
Object get arguments => _routing.args;
/// give name from current route
get currentRoute => _routing.current;
String get currentRoute => _routing.current;
/// give name from previous route
get previousRoute => _routing.previous;
String get previousRoute => _routing.previous;
/// check if snackbar is open
bool get isSnackbarOpen => _routing.isSnackbar;
... ... @@ -747,10 +747,11 @@ class GetImpl implements GetService {
MediaQueryData get mediaQuery => MediaQuery.of(context);
/// Check if dark mode theme is enable
get isDarkMode => (theme.brightness == Brightness.dark);
bool get isDarkMode => (theme.brightness == Brightness.dark);
/// Check if dark mode theme is enable on platform on android Q+
get isPlatformDarkMode => (mediaQuery.platformBrightness == Brightness.dark);
bool get isPlatformDarkMode =>
(mediaQuery.platformBrightness == Brightness.dark);
/// give access to Theme.of(context).iconTheme.color
Color get iconColor => Theme.of(context).iconTheme.color;
... ...
... ... @@ -124,7 +124,8 @@ class GetMaterialApp extends StatelessWidget {
customTransition: match.route.customTransition,
binding: unknownRoute.binding,
bindings: unknownRoute.bindings,
duration: (transitionDuration ?? unknownRoute.transitionDuration),
transitionDuration:
(transitionDuration ?? unknownRoute.transitionDuration),
transition: unknownRoute.transition,
popGesture: unknownRoute.popGesture,
fullscreenDialog: unknownRoute.fullscreenDialog,
... ... @@ -141,7 +142,8 @@ class GetMaterialApp extends StatelessWidget {
customTransition: match.route.customTransition,
binding: match.route.binding,
bindings: match.route.bindings,
duration: (transitionDuration ?? match.route.transitionDuration),
transitionDuration:
(transitionDuration ?? match.route.transitionDuration),
transition: match.route.transition,
popGesture: match.route.popGesture,
fullscreenDialog: match.route.fullscreenDialog,
... ... @@ -161,7 +163,8 @@ class GetMaterialApp extends StatelessWidget {
opaque: match.route.opaque,
binding: match.route.binding,
bindings: match.route.bindings,
duration: (transitionDuration ?? match.route.transitionDuration),
transitionDuration:
(transitionDuration ?? match.route.transitionDuration),
transition: match.route.transition,
popGesture: match.route.popGesture,
fullscreenDialog: match.route.fullscreenDialog,
... ...
abstract class Bindings {
dependencies();
void dependencies();
}
// abstract class INavigation {}
... ...
... ... @@ -5,42 +5,111 @@ 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 'package:get/utils.dart';
import 'bindings_interface.dart';
import 'custom_transition.dart';
import 'transitions_filter.dart';
import 'default_transitions.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 Alignment alignment;
final GetPageBuilder page;
final CustomTransition customTransition;
final Bindings binding;
final Map<String, String> parameter;
final List<Bindings> bindings;
class GetPageRoute<T> extends PageRoute<T> {
GetPageRoute({
// this.transitionComponent,
RouteSettings settings,
this.duration,
this.transition,
this.binding,
@required this.page,
this.bindings,
this.transitionDuration = const Duration(milliseconds: 400),
this.opaque = true,
this.parameter,
this.curve,
this.alignment,
this.fullscreenDialog = false,
this.curve = Curves.linear,
this.transition,
this.popGesture,
this.customTransition,
}) : super(
pageBuilder: (context, anim1, anim2) {
this.barrierDismissible = false,
this.barrierColor,
this.binding,
this.bindings,
this.page,
this.barrierLabel,
this.maintainState = true,
bool fullscreenDialog = false,
}) : assert(opaque != null),
assert(barrierDismissible != null),
assert(maintainState != null),
assert(fullscreenDialog != null),
super(settings: settings, fullscreenDialog: fullscreenDialog);
@override
final Duration transitionDuration;
final GetPageBuilder page;
final CustomTransition customTransition;
final Bindings binding;
final Map<String, String> parameter;
final List<Bindings> bindings;
@override
final bool opaque;
final bool popGesture;
@override
final bool barrierDismissible;
final Transition transition;
final Curve curve;
final Alignment alignment;
@override
final Color barrierColor;
@override
final String barrierLabel;
@override
final bool maintainState;
@override
bool canTransitionTo(TransitionRoute<dynamic> nextRoute) {
// Don't perform outgoing animation if the next route is a fullscreen dialog.
return nextRoute is PageRoute && !nextRoute.fullscreenDialog;
}
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,
);
}
@override
Widget buildPage(BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation) {
if (binding != null) {
binding.dependencies();
}
... ... @@ -51,15 +120,7 @@ class GetPageRoute<T> extends PageRouteBuilder<T> {
}
GetConfig.currentRoute = settings.name;
return page();
},
settings: settings,
);
@override
final bool opaque;
@override
final bool fullscreenDialog;
}
static bool isPopGestureInProgress(PageRoute<dynamic> route) {
return route.navigator.userGestureInProgress;
... ... @@ -68,24 +129,14 @@ class GetPageRoute<T> extends PageRouteBuilder<T> {
bool get popGestureInProgress => isPopGestureInProgress(this);
@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;
}
@override
Widget buildTransitions(BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation, Widget child) {
if (fullscreenDialog != null &&
transition == null &&
customTransition == null) {
final bool linearTransition = isPopGestureInProgress(this);
if (fullscreenDialog && transition == null) {
return CupertinoFullscreenDialogTransition(
primaryRouteAnimation: animation,
secondaryRouteAnimation: secondaryAnimation,
child: child,
linearTransition: linearTransition,
);
linearTransition: true);
}
if (this.customTransition != null) {
... ... @@ -102,14 +153,10 @@ class GetPageRoute<T> extends PageRouteBuilder<T> {
child: child)
: child);
}
final curvedAnimation = CurvedAnimation(
parent: animation,
curve: this.curve ?? Curves.linear,
);
if (transition == null) {
if (Get.customTransition != null) {
return Get.customTransition.buildTransition(
switch (transition ?? Get.defaultTransition) {
case Transition.leftToRight:
return SlideLeftTransition().buildTransitions(
context,
curve,
alignment,
... ... @@ -121,15 +168,13 @@ class GetPageRoute<T> extends PageRouteBuilder<T> {
onStartPopGesture: () => _startPopGesture<T>(this),
child: child)
: child);
}
if (Get.defaultTransition != null) {
return TransitionFilter.newTransitionComponent(Get.defaultTransition)
.buildChildWithTransition(
case Transition.downToUp:
return SlideDownTransition().buildTransitions(
context,
curve,
alignment,
curvedAnimation,
animation,
secondaryAnimation,
popGesture ?? Get.defaultPopGesture
? _CupertinoBackGestureDetector<T>(
... ... @@ -137,27 +182,27 @@ class GetPageRoute<T> extends PageRouteBuilder<T> {
onStartPopGesture: () => _startPopGesture<T>(this),
child: child)
: child);
}
return Theme.of(context).pageTransitionsTheme.buildTransitions(
this,
case Transition.upToDown:
return SlideTopTransition().buildTransitions(
context,
curve,
alignment,
animation,
secondaryAnimation,
GetPlatform.isIOS
popGesture ?? Get.defaultPopGesture
? _CupertinoBackGestureDetector<T>(
enabledCallback: () => _isPopGestureEnabled<T>(this),
onStartPopGesture: () => _startPopGesture<T>(this),
child: child)
: child);
}
return TransitionFilter.newTransitionComponent(transition)
.buildChildWithTransition(
case Transition.rightToLeft:
return SlideRightTransition().buildTransitions(
context,
curve,
alignment,
curvedAnimation,
animation,
secondaryAnimation,
popGesture ?? Get.defaultPopGesture
? _CupertinoBackGestureDetector<T>(
... ... @@ -165,39 +210,173 @@ class GetPageRoute<T> extends PageRouteBuilder<T> {
onStartPopGesture: () => _startPopGesture<T>(this),
child: child)
: child);
}
@override
Duration get transitionDuration =>
this.duration ?? Duration(milliseconds: 400);
case Transition.zoom:
return ZoomInTransition().buildTransitions(
context,
curve,
alignment,
animation,
secondaryAnimation,
popGesture ?? Get.defaultPopGesture
? _CupertinoBackGestureDetector<T>(
enabledCallback: () => _isPopGestureEnabled<T>(this),
onStartPopGesture: () => _startPopGesture<T>(this),
child: child)
: child);
static bool _isPopGestureEnabled<T>(PageRoute<T> route) {
if (route.isFirst) return false;
case Transition.fadeIn:
return FadeInTransition().buildTransitions(
context,
curve,
alignment,
animation,
secondaryAnimation,
popGesture ?? Get.defaultPopGesture
? _CupertinoBackGestureDetector<T>(
enabledCallback: () => _isPopGestureEnabled<T>(this),
onStartPopGesture: () => _startPopGesture<T>(this),
child: child)
: child);
if (route.willHandlePopInternally) return false;
case Transition.rightToLeftWithFade:
return RightToLeftFadeTransition().buildTransitions(
context,
curve,
alignment,
animation,
secondaryAnimation,
popGesture ?? Get.defaultPopGesture
? _CupertinoBackGestureDetector<T>(
enabledCallback: () => _isPopGestureEnabled<T>(this),
onStartPopGesture: () => _startPopGesture<T>(this),
child: child)
: child);
if (route.hasScopedWillPopCallback) return false;
case Transition.leftToRightWithFade:
return LeftToRightFadeTransition().buildTransitions(
context,
curve,
alignment,
animation,
secondaryAnimation,
popGesture ?? Get.defaultPopGesture
? _CupertinoBackGestureDetector<T>(
enabledCallback: () => _isPopGestureEnabled<T>(this),
onStartPopGesture: () => _startPopGesture<T>(this),
child: child)
: child);
if (route.fullscreenDialog) return false;
case Transition.cupertino:
return CupertinoTransitions().buildTransitions(
context,
curve,
alignment,
animation,
secondaryAnimation,
popGesture ?? Get.defaultPopGesture
? _CupertinoBackGestureDetector<T>(
enabledCallback: () => _isPopGestureEnabled<T>(this),
onStartPopGesture: () => _startPopGesture<T>(this),
child: child)
: child);
if (route.animation.status != AnimationStatus.completed) return false;
case Transition.size:
return SizeTransitions().buildTransitions(
context,
curve,
alignment,
animation,
secondaryAnimation,
popGesture ?? Get.defaultPopGesture
? _CupertinoBackGestureDetector<T>(
enabledCallback: () => _isPopGestureEnabled<T>(this),
onStartPopGesture: () => _startPopGesture<T>(this),
child: child)
: child);
if (route.secondaryAnimation.status != AnimationStatus.dismissed)
return false;
case Transition.fade:
return FadeUpwardsPageTransitionsBuilder().buildTransitions(
this,
context,
animation,
secondaryAnimation,
popGesture ?? Get.defaultPopGesture
? _CupertinoBackGestureDetector<T>(
enabledCallback: () => _isPopGestureEnabled<T>(this),
onStartPopGesture: () => _startPopGesture<T>(this),
child: child)
: child);
if (isPopGestureInProgress(route)) return false;
case Transition.topLevel:
return ZoomPageTransitionsBuilder().buildTransitions(
this,
context,
animation,
secondaryAnimation,
popGesture ?? Get.defaultPopGesture
? _CupertinoBackGestureDetector<T>(
enabledCallback: () => _isPopGestureEnabled<T>(this),
onStartPopGesture: () => _startPopGesture<T>(this),
child: child)
: child);
return true;
}
case Transition.native:
if (GetPlatform.isIOS)
return CupertinoTransitions().buildTransitions(
context,
curve,
alignment,
animation,
secondaryAnimation,
popGesture ?? Get.defaultPopGesture
? _CupertinoBackGestureDetector<T>(
enabledCallback: () => _isPopGestureEnabled<T>(this),
onStartPopGesture: () => _startPopGesture<T>(this),
child: child)
: child);
static _CupertinoBackGestureController<T> _startPopGesture<T>(
PageRoute<T> route) {
assert(_isPopGestureEnabled(route));
return FadeInTransition().buildTransitions(
context,
curve,
alignment,
animation,
secondaryAnimation,
popGesture ?? Get.defaultPopGesture
? _CupertinoBackGestureDetector<T>(
enabledCallback: () => _isPopGestureEnabled<T>(this),
onStartPopGesture: () => _startPopGesture<T>(this),
child: child)
: child);
return _CupertinoBackGestureController<T>(
navigator: route.navigator,
controller: route.controller,
);
default:
if (GetPlatform.isIOS)
return CupertinoTransitions().buildTransitions(
context,
curve,
alignment,
animation,
secondaryAnimation,
popGesture ?? Get.defaultPopGesture
? _CupertinoBackGestureDetector<T>(
enabledCallback: () => _isPopGestureEnabled<T>(this),
onStartPopGesture: () => _startPopGesture<T>(this),
child: child)
: child);
return FadeInTransition().buildTransitions(
context,
curve,
alignment,
animation,
secondaryAnimation,
popGesture ?? Get.defaultPopGesture
? _CupertinoBackGestureDetector<T>(
enabledCallback: () => _isPopGestureEnabled<T>(this),
onStartPopGesture: () => _startPopGesture<T>(this),
child: child)
: child);
}
}
}
... ... @@ -410,655 +589,3 @@ class _CupertinoBackGestureController<T> {
}
}
}
// 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();
// }
// }
// }
... ...
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'transitions_component.dart';
class LeftToRightFadeTransition extends TransitionComponent {
@override
Widget buildChildWithTransition(
class LeftToRightFadeTransition {
Widget buildTransitions(
BuildContext context,
Curve curve,
Alignment alignment,
... ... @@ -29,9 +27,8 @@ class LeftToRightFadeTransition extends TransitionComponent {
}
}
class RightToLeftFadeTransition extends TransitionComponent {
@override
Widget buildChildWithTransition(
class RightToLeftFadeTransition {
Widget buildTransitions(
BuildContext context,
Curve curve,
Alignment alignment,
... ... @@ -56,9 +53,8 @@ class RightToLeftFadeTransition extends TransitionComponent {
}
}
class NoTransition extends TransitionComponent {
@override
Widget buildChildWithTransition(
class NoTransition {
Widget buildTransitions(
BuildContext context,
Curve curve,
Alignment alignment,
... ... @@ -69,9 +65,8 @@ class NoTransition extends TransitionComponent {
}
}
class FadeInTransition extends TransitionComponent {
@override
Widget buildChildWithTransition(
class FadeInTransition {
Widget buildTransitions(
BuildContext context,
Curve curve,
Alignment alignment,
... ... @@ -82,9 +77,8 @@ class FadeInTransition extends TransitionComponent {
}
}
class SlideDownTransition extends TransitionComponent {
@override
Widget buildChildWithTransition(
class SlideDownTransition {
Widget buildTransitions(
BuildContext context,
Curve curve,
Alignment alignment,
... ... @@ -101,9 +95,8 @@ class SlideDownTransition extends TransitionComponent {
}
}
class SlideLeftTransition extends TransitionComponent {
@override
Widget buildChildWithTransition(
class SlideLeftTransition {
Widget buildTransitions(
BuildContext context,
Curve curve,
Alignment alignment,
... ... @@ -120,9 +113,8 @@ class SlideLeftTransition extends TransitionComponent {
}
}
class SlideRightTransition extends TransitionComponent {
@override
Widget buildChildWithTransition(
class SlideRightTransition {
Widget buildTransitions(
BuildContext context,
Curve curve,
Alignment alignment,
... ... @@ -139,9 +131,8 @@ class SlideRightTransition extends TransitionComponent {
}
}
class SlideTopTransition extends TransitionComponent {
@override
Widget buildChildWithTransition(
class SlideTopTransition {
Widget buildTransitions(
BuildContext context,
Curve curve,
Alignment alignment,
... ... @@ -158,9 +149,8 @@ class SlideTopTransition extends TransitionComponent {
}
}
class ZoomInTransition extends TransitionComponent {
@override
Widget buildChildWithTransition(
class ZoomInTransition {
Widget buildTransitions(
BuildContext context,
Curve curve,
Alignment alignment,
... ... @@ -174,9 +164,8 @@ class ZoomInTransition extends TransitionComponent {
}
}
class SizeTransitions extends TransitionComponent {
@override
Widget buildChildWithTransition(
class SizeTransitions {
Widget buildTransitions(
BuildContext context,
Curve curve,
Alignment alignment,
... ... @@ -196,9 +185,8 @@ class SizeTransitions extends TransitionComponent {
}
}
class CupertinoTransitions extends TransitionComponent {
@override
Widget buildChildWithTransition(
class CupertinoTransitions {
Widget buildTransitions(
BuildContext context,
Curve curve,
Alignment alignment,
... ...
... ... @@ -10,6 +10,7 @@ enum Transition {
rightToLeftWithFade,
leftToRightWithFade,
zoom,
topLevel,
noTransition,
cupertino,
cupertinoDialog,
... ...
... ... @@ -100,6 +100,16 @@ class GetImplXState<T extends DisposableInterface> extends State<GetX<T>> {
final observer = getObs;
getObs = _observer;
final result = widget.builder(controller);
if (!_observer.canUpdate) {
throw """
[Get] the improper use of a GetX has been detected.
You should only use GetX or Obx for the specific widget that will be updated.
If you are seeing this error, you probably did not insert any observable variables into GetX/Obx
or insert them outside the scope that GetX considers suitable for an update
(example: GetX => HeavyWidget => variableObservable).
If you need to update a parent widget and a child widget, wrap each one in an Obx/GetX.
""";
}
getObs = observer;
return result;
}
... ...
... ... @@ -15,6 +15,10 @@ class _RxImpl<T> implements RxInterface<T> {
return _value;
}
bool get canUpdate {
return _subscriptions.length > 0;
}
T call([T v]) {
if (v != null) {
this.value = v;
... ... @@ -84,6 +88,10 @@ class RxMap<K, V> extends RxInterface implements Map<K, V> {
String get string => value.toString();
bool get canUpdate {
return _subscriptions.length > 0;
}
@override
void close() {
_subscriptions.forEach((observable, subscription) {
... ... @@ -250,6 +258,10 @@ class RxList<E> extends Iterable<E> implements RxInterface<E> {
@override
bool get isEmpty => value.isEmpty;
bool get canUpdate {
return _subscriptions.length > 0;
}
@override
bool get isNotEmpty => value.isNotEmpty;
... ... @@ -419,8 +431,6 @@ RxInterface getObs;
typedef bool Condition();
typedef E ChildrenListComposer<S, E>(S value);
class RxBool extends _RxImpl<bool> {
RxBool([bool initial]) {
_value = initial;
... ...
... ... @@ -8,6 +8,8 @@ abstract class RxInterface<T> {
/// add listener to stream
addListener(Stream<T> rxGetx);
bool get canUpdate;
/// close stream
close() {
subject?.close();
... ... @@ -15,14 +17,8 @@ abstract class RxInterface<T> {
StreamController<T> subject;
/// Convert value on string
// String get string;
/// Calls [callback] with current value, when the value changes.
StreamSubscription<T> listen(ValueCallback<T> callback);
/// Maps the changes into a [Stream] of [S]
// Stream<S> map<S>(S mapper(T data));
}
abstract class DisposableInterface {
... ...
... ... @@ -54,6 +54,16 @@ class _ObxState extends State<Obx> {
final observer = getObs;
getObs = _observer;
final result = widget.builder();
if (!_observer.canUpdate) {
throw """
[Get] the improper use of a GetX has been detected.
You should only use GetX or Obx for the specific widget that will be updated.
If you are seeing this error, you probably did not insert any observable variables into GetX/Obx
or insert them outside the scope that GetX considers suitable for an update
(example: GetX => HeavyWidget => variableObservable).
If you need to update a parent widget and a child widget, wrap each one in an Obx/GetX.
""";
}
getObs = observer;
return result;
}
... ...
name: get
description: Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
version: 3.2.1
version: 3.2.2
homepage: https://github.com/jonataslaw/get
environment:
... ...