Browse Source

Merge pull request #1 from SvenSchoene/feature_add_no_transition

add option for using no transition on route change
Sven Schöne 6 years ago
parent
commit
0d07e9f64c
3 changed files with 15 additions and 0 deletions
  1. 5 0
      example/lib/components/home/home_component.dart
  2. 1 0
      lib/src/common.dart
  3. 9 0
      lib/src/router.dart

+ 5 - 0
example/lib/components/home/home_component.dart

@@ -103,6 +103,7 @@ class HomeComponentState extends State<HomeComponent> {
       menuButton(context, "Preset (Fade In)", "preset-fade"),
       menuButton(context, "Preset (Global transition)", "fixed-trans"),
       menuButton(context, "Custom Transition", "custom"),
+      menuButton(context, "No Transition", "noTransition"),
       menuButton(context, "Navigator Result", "pop-result"),
       menuButton(context, "Function Call", "function-call"),
       new Padding(
@@ -174,6 +175,10 @@ class HomeComponentState extends State<HomeComponent> {
         message =
             "When you close this screen you should see the current day of the week";
         result = "Today is ${_daysOfWeek[new DateTime.now().weekday - 1]}!";
+      } else if (key == "noTransition") {
+        hexCode = "#9BFF94";
+        message = "This should have appeared without a transition.";
+        transitionType = TransitionType.noTransition;
       }
 
       String route = "/demo?message=$message&color_hex=$hexCode";

+ 1 - 0
lib/src/common.dart

@@ -45,6 +45,7 @@ enum TransitionType {
   inFromRight,
   inFromBottom,
   fadeIn,
+  noTransition,
   custom, // if using custom then you must also provide a transition
 }
 

+ 9 - 0
lib/src/router.dart

@@ -134,6 +134,8 @@ class Router {
         var routeTransitionsBuilder;
         if (transition == TransitionType.custom) {
           routeTransitionsBuilder = transitionsBuilder;
+        } else if (transition == TransitionType.noTransition) {
+          routeTransitionsBuilder = _noTransitionBuilder(transition);
         } else {
           routeTransitionsBuilder = _standardTransitionsBuilder(transition);
         }
@@ -154,6 +156,13 @@ class Router {
     );
   }
 
+  RouteTransitionsBuilder _noTransitionBuilder(TransitionType transitionType) {
+    return (BuildContext context, Animation<double> animation,
+        Animation<double> secondaryAnimation, Widget child) {
+      return child;
+    };
+  }
+
   RouteTransitionsBuilder _standardTransitionsBuilder(
       TransitionType transitionType) {
     return (BuildContext context, Animation<double> animation,