Last active
May 22, 2023 09:19
-
-
Save rutvik110/3c220852970093cbb5b4c2611d6aab0a to your computer and use it in GitHub Desktop.
Custom navigation route that better support hero animations.
This file contains hidden or 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
// Couldn't find the original developer and the gist of this code. | |
// Full credit goes to the original developer for the implementation of [HeroDialogRoute]. | |
import 'package:flutter/material.dart'; | |
class HeroDialogRoute<T> extends PageRoute<T> { | |
HeroDialogRoute({required this.builder}) : super(); | |
final WidgetBuilder builder; | |
@override | |
bool get opaque => false; | |
@override | |
bool get barrierDismissible => true; | |
@override | |
Duration get transitionDuration => const Duration(milliseconds: 300); | |
@override | |
bool get maintainState => true; | |
@override | |
Color get barrierColor => Colors.black54; | |
@override | |
Widget buildTransitions(BuildContext context, Animation<double> animation, | |
Animation<double> secondaryAnimation, Widget child,) { | |
return FadeTransition( | |
opacity: CurvedAnimation( | |
parent: animation, | |
curve: Curves.decelerate, | |
), | |
child: child, | |
); | |
} | |
@override | |
Widget buildPage(BuildContext context, Animation<double> animation, | |
Animation<double> secondaryAnimation,) { | |
return builder(context); | |
} | |
@override | |
String? get barrierLabel => 'Dismissable Dialog'; | |
} | |
// Build the next route where the second hero widget lies using [HeroDialogRoute]. | |
await Navigator.push( | |
context, | |
HeroDialogRoute<void>( | |
builder: (BuildContext context) { | |
return SizedBox(); | |
}, | |
), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment