Created
October 29, 2022 12:08
-
-
Save hawkkiller/4e39fab0a1b4d3c1dbecfd38144df7e2 to your computer and use it in GitHub Desktop.
No Transition Page Dart, useful for nested nav
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
class NoTransitionPage extends Page<Object> { | |
const NoTransitionPage({ | |
required this.child, | |
this.fullscreenDialog = false, | |
this.maintainState = true, | |
this.barrierColor, | |
this.barrierLabel, | |
}); | |
final Widget child; | |
final Color? barrierColor; | |
final String? barrierLabel; | |
/// {@macro flutter.widgets.ModalRoute.maintainState} | |
final bool maintainState; | |
/// {@macro flutter.widgets.PageRoute.fullscreenDialog} | |
final bool fullscreenDialog; | |
@override | |
Route<Object> createRoute(BuildContext context) => | |
_NoTransitionPageRoute(this); | |
} | |
class _NoTransitionPageRoute<T> extends PageRoute<T> { | |
_NoTransitionPageRoute(this._page); | |
final NoTransitionPage _page; | |
@override | |
bool get fullscreenDialog => _page.fullscreenDialog; | |
@override | |
Color? get barrierColor => _page.barrierColor; | |
@override | |
String? get barrierLabel => _page.barrierLabel; | |
@override | |
Widget buildPage( | |
BuildContext context, | |
Animation<double> animation, | |
Animation<double> secondaryAnimation, | |
) => | |
_page.child; | |
@override | |
bool get maintainState => _page.maintainState; | |
@override | |
Duration get transitionDuration => Duration.zero; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment