Created
July 10, 2020 20:14
-
-
Save samuelematias/24052e2693d22d422417cc1703c3e1ee to your computer and use it in GitHub Desktop.
flutter modal with custom/animated transition
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 AnimatedModal extends PageRouteBuilder { | |
AnimatedModal({ | |
@required BuildContext context, | |
@required Widget modalContent, | |
double overlayHeight = 50.0, | |
}) : super( | |
opaque: false, | |
transitionsBuilder: (BuildContext context, | |
Animation<double> animation, | |
Animation<double> secondaryAnimation, | |
Widget child) { | |
return ScaleTransition( | |
scale: Tween<double>( | |
begin: 0.0, | |
end: 1.0, | |
).animate( | |
CurvedAnimation( | |
parent: animation, | |
curve: Interval( | |
0.00, | |
0.50, | |
curve: Curves.linear, | |
), | |
), | |
), | |
child: ScaleTransition( | |
scale: Tween<double>( | |
begin: 1.5, | |
end: 1.0, | |
).animate( | |
CurvedAnimation( | |
parent: animation, | |
curve: Interval( | |
0.50, | |
1.00, | |
curve: Curves.linear, | |
), | |
), | |
), | |
child: child, | |
), | |
); | |
}, | |
pageBuilder: ( | |
BuildContext context, | |
Animation<double> animation, | |
Animation<double> secondaryAnimation, | |
) { | |
return GestureDetector( | |
onTap: () => Navigator.pop(context), | |
child: Scaffold( | |
backgroundColor: Colors.black45, | |
body: GestureDetector( | |
onTap: () {}, | |
child: Container( | |
decoration: BoxDecoration( | |
color: Colors.white, | |
borderRadius: BorderRadius.only( | |
topLeft: Radius.circular(4), | |
topRight: Radius.circular(4), | |
), | |
), | |
margin: EdgeInsetsDirectional.only(top: overlayHeight), | |
height: MediaQuery.of(context).size.height, | |
width: MediaQuery.of(context).size.width, | |
child: Column( | |
children: <Widget>[ | |
Container( | |
margin: EdgeInsets.only(top: 12.0), | |
width: 40.0, | |
height: 4.0, | |
decoration: BoxDecoration( | |
color: Color(0xFFDCDCDC), | |
borderRadius: BorderRadius.all(Radius.circular(6)), | |
), | |
), | |
modalContent, | |
], | |
), | |
), | |
), | |
), | |
); | |
}, | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment