Created
February 25, 2020 11:48
-
-
Save agreensh/e5a05162b4fbdc823324dfb2af3f1670 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
| import 'package:flutter/material.dart'; | |
| void main() => runApp(MyApp()); | |
| class MyApp extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| title: 'Flutter Demo', | |
| theme: ThemeData( | |
| primarySwatch: Colors.blue, | |
| ), | |
| home: MyHomePage(), | |
| debugShowCheckedModeBanner: false, | |
| ); | |
| } | |
| } | |
| class MyHomePage extends StatefulWidget { | |
| MyHomePage({Key key}) : super(key: key); | |
| @override | |
| _MyHomePageState createState() => _MyHomePageState(); | |
| } | |
| class _MyHomePageState extends State<MyHomePage> { | |
| int _counter = 0; | |
| void _incrementCounter() { | |
| setState(() { | |
| _counter++; | |
| }); | |
| } | |
| // this is used just to get AppBar height. | |
| final AppBar _appBar = AppBar( | |
| title: const Text(''), | |
| ); | |
| void _showTopModalSheet() { | |
| showGeneralDialog( | |
| context: context, | |
| barrierDismissible: true, | |
| transitionDuration: Duration(milliseconds: 400), | |
| barrierLabel: MaterialLocalizations.of(context).dialogLabel, | |
| barrierColor: Colors.black.withOpacity(0.6), | |
| pageBuilder: (context, _, __) { | |
| return Column( | |
| mainAxisAlignment: MainAxisAlignment.start, | |
| children: <Widget>[ | |
| Container( | |
| width: MediaQuery.of(context).size.width, | |
| color: Colors.white, | |
| child: Card( | |
| elevation: 0.0, | |
| child: ListView( | |
| shrinkWrap: true, | |
| children: <Widget>[ | |
| ListTile( | |
| title: Text('Top modal 1'), | |
| onTap: () { | |
| // do item 1 action | |
| Navigator.of(context).pop(); | |
| }, | |
| ), | |
| Divider(), | |
| ListTile( | |
| title: Text('Top modal 2'), | |
| onTap: () { | |
| // do item 2 action | |
| Navigator.of(context).pop(); | |
| }, | |
| ), | |
| Divider(), | |
| ListTile( | |
| title: Text('Top modal 3'), | |
| onTap: () { | |
| // do item 3 action | |
| Navigator.of(context).pop(); | |
| }, | |
| ), | |
| ], | |
| ), | |
| ), | |
| ), | |
| ], | |
| ); | |
| }, | |
| transitionBuilder: (context, animation, secondaryAnimation, child) { | |
| return SlideTransition( | |
| position: CurvedAnimation( | |
| parent: animation, | |
| curve: Curves.easeOut, | |
| ).drive(Tween<Offset>( | |
| begin: Offset(0.0, -1.0), | |
| end: Offset( | |
| 0.0, | |
| // need to go past appbar and status bar (if any) OR put to 0.0 to cover the app bar | |
| ((_appBar.preferredSize.height + | |
| MediaQuery.of(context).padding.top) / | |
| MediaQuery.of(context).size.height)), | |
| )), | |
| child: child, | |
| ); | |
| }, | |
| ); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| appBar: AppBar( | |
| title: const Text('From Top'), | |
| leading: IconButton( | |
| icon: Icon(Icons.menu, size: 32), | |
| onPressed: () => _showTopModalSheet(), | |
| ), | |
| ), | |
| body: Center( | |
| child: Column( | |
| mainAxisAlignment: MainAxisAlignment.center, | |
| children: <Widget>[ | |
| Text( | |
| 'You have pushed the button this many times:', | |
| ), | |
| Text( | |
| '$_counter', | |
| style: Theme.of(context).textTheme.headline4, | |
| ), | |
| ], | |
| ), | |
| ), | |
| floatingActionButton: FloatingActionButton( | |
| onPressed: _incrementCounter, | |
| tooltip: 'Increment', | |
| child: Icon(Icons.add), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment