Skip to content

Instantly share code, notes, and snippets.

@mutant0113
Created July 25, 2020 12:36
Show Gist options
  • Save mutant0113/047d0138b089684d1f01e296f8089245 to your computer and use it in GitHub Desktop.
Save mutant0113/047d0138b089684d1f01e296f8089245 to your computer and use it in GitHub Desktop.
FlutterContainerTransformShrink
class _PageAState extends State<PageA> {
...
// A widget for page transition between the `pageA` and `pageB` after tapping the `FAB button`.
Widget get _pageTransition {
// Dismiss ripple widget if `_pageTransitionRect` is null.
if (_pageTransitionRect == null) {
return Container();
}
return AnimatedPositioned.fromRect(
rect: _pageTransitionRect,
duration: Duration(milliseconds: 300),
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: _FabButtonColor,
),
),
onEnd: () {
bool shouldNavigatePage = _pageTransitionRect != _fabButtonRect;
if (shouldNavigatePage) {
Navigator.push(
context,
FadeRouteBuilder(page: PageB()),
).then((_) {
// Shrink back to the normal FAB button size.
setState(() => _pageTransitionRect = _fabButtonRect);
});
} else {
// Dismiss ripple widget after shrinking finishes.
setState(() => _pageTransitionRect = null);
}
},
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment