Created
May 12, 2020 14:04
-
-
Save nick45chen/e08cc8371ad9768479399b0a62d8a353 to your computer and use it in GitHub Desktop.
ModalBottomSheet
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/cupertino.dart'; | |
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
// This widget is the root of your application. | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
visualDensity: VisualDensity.adaptivePlatformDensity, | |
), | |
home: PageA(), | |
); | |
} | |
} | |
class PageA extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(''), | |
actions: <Widget>[ | |
IconButton( | |
icon: Icon(Icons.exit_to_app), | |
onPressed: () { | |
Navigator.pop(context); | |
}, | |
) | |
], | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
RaisedButton( | |
child: Text('Go PageB'), | |
onPressed: () { | |
Navigator.of(context).push( | |
CupertinoPageRoute(fullscreenDialog: true, builder: (context) => PageB()), | |
); | |
}, | |
), | |
RaisedButton( | |
child: Text('Go PageC'), | |
onPressed: () { | |
Navigator.push( | |
context, | |
MaterialPageRoute(builder: (context) => PageC()), | |
); | |
}, | |
), | |
RaisedButton( | |
child: Text('Go PageC full screen'), | |
onPressed: () { | |
Navigator.push( | |
context, | |
MaterialPageRoute(builder: (context) => PageC(), fullscreenDialog: true), | |
); | |
}, | |
), | |
RaisedButton( | |
child: Text('bottom sheet page'), | |
onPressed: () { | |
showModalBottomSheet( | |
context: context, | |
isScrollControlled: true, | |
backgroundColor: Colors.transparent, | |
builder: (context) => Container( | |
height: MediaQuery.of(context).size.height * 0.9, | |
decoration: new BoxDecoration( | |
color: Colors.white, | |
borderRadius: new BorderRadius.only( | |
topLeft: const Radius.circular(25.0), | |
topRight: const Radius.circular(25.0), | |
), | |
), | |
child: Column( | |
children: <Widget>[ | |
Container( | |
width: double.infinity, | |
height: 56, | |
color: Color(0xd5d5d45), | |
child: Row( | |
children: <Widget>[ | |
Padding( | |
padding: const EdgeInsets.only(left: 20, top: 20, bottom: 10), | |
child: GestureDetector( | |
child: Text( | |
'關閉', | |
style: TextStyle(color: Colors.blue), | |
), | |
onTap: () => Navigator.pop(context), | |
), | |
) | |
], | |
), | |
), | |
], | |
)), | |
); | |
}, | |
) | |
], | |
), | |
), | |
); | |
} | |
} | |
class PageB extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(''), | |
), | |
body: Container( | |
color: Color(0xf5f5f5f5), | |
child: Center(child: Text('PageB')), | |
), | |
); | |
} | |
} | |
class PageC extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(''), | |
), | |
body: Center( | |
child: Text('PageC'), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment