Created
November 1, 2019 12:42
-
-
Save Nash0x7E2/4a38ef914281176427bc8136a4f74fc4 to your computer and use it in GitHub Desktop.
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
// MIT License | |
// | |
// Copyright (c) 2019 Neevash Ramdial | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy | |
// of this software and associated documentation files (the "Software"), to deal | |
// in the Software without restriction, including without limitation the rights | |
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
// copies of the Software, and to permit persons to whom the Software is | |
// furnished to do so, subject to the following conditions: | |
// | |
// The above copyright notice and this permission notice shall be included in all | |
// copies or substantial portions of the Software. | |
// | |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
// SOFTWARE. | |
// | |
import 'package:flutter/material.dart'; | |
void main() { | |
runApp( | |
MaterialApp( | |
home: RoutingDemo(), | |
), | |
); | |
} | |
class RoutingDemo extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: SafeArea( | |
child: Align( | |
alignment: Alignment.center, | |
child: ListTile( | |
onTap: () { | |
Navigator.push( | |
context, | |
CustomRoute( | |
builder: (BuildContext context) { | |
return PageTwo(); | |
}, | |
), | |
); | |
}, | |
title: Text('Surprise?'), | |
subtitle: Text(':)'), | |
), | |
), | |
), | |
); | |
} | |
} | |
class PageTwo extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return AnimatedPadding( | |
padding: MediaQuery.of(context).viewInsets + | |
EdgeInsets.symmetric(vertical: 30.0, horizontal: 24.0), | |
curve: Curves.ease, | |
duration: const Duration(milliseconds: 100), | |
child: Material( | |
shape: RoundedRectangleBorder( | |
borderRadius: BorderRadius.circular( | |
24.0, | |
), | |
), | |
color: Colors.blueAccent, | |
child: Center( | |
child: Image.asset( | |
'assets/batman.png', | |
height: 100.0, | |
)), | |
), | |
); | |
} | |
} | |
class CustomRoute extends PopupRoute { | |
final WidgetBuilder builder; | |
final bool dismissible; | |
final String label; | |
final Color color; | |
CustomRoute({ | |
@required this.builder, | |
this.dismissible = true, | |
this.label, | |
this.color, | |
RouteSettings setting, | |
}) : super(settings: setting); | |
@override | |
Color get barrierColor => color; | |
@override | |
bool get barrierDismissible => dismissible; | |
@override | |
String get barrierLabel => label; | |
@override | |
Widget buildPage( | |
BuildContext context, | |
Animation<double> animation, | |
Animation<double> secondaryAnimation, | |
) { | |
return builder(context); | |
} | |
@override | |
Widget buildTransitions( | |
BuildContext context, | |
Animation<double> animation, | |
Animation<double> secondaryAnimation, | |
Widget child, | |
) { | |
return RotationTransition( | |
turns: animation, | |
child: ScaleTransition( | |
scale: animation, | |
child: child, | |
), | |
); | |
} | |
@override | |
Duration get transitionDuration => const Duration(milliseconds: 400); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment