Created
May 2, 2018 10:18
-
-
Save shyjuzz/a58812e63eb671a4e54789d8cafd9d17 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'; | |
class BottomSheetDemo extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return new MaterialApp( | |
title: 'Flutter Demo', | |
theme: new ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: new BottomSheet(), | |
); | |
} | |
} | |
class BottomSheet extends StatefulWidget { | |
@override | |
_MyHomePageState createState() => new _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<BottomSheet> { | |
final _scaffoldKey = new GlobalKey<ScaffoldState>(); | |
VoidCallback _showPersBottomSheetCallBack; | |
@override | |
void initState() { | |
super.initState(); | |
_showPersBottomSheetCallBack = _showBottomSheet; | |
} | |
void _showBottomSheet() { | |
setState(() { | |
_showPersBottomSheetCallBack = null; | |
}); | |
_scaffoldKey.currentState | |
.showBottomSheet((context) { | |
return new Container( | |
height: 200.0, | |
color: Colors.greenAccent, | |
child: new Center( | |
child: new Text("Hi BottomSheet"), | |
), | |
); | |
}) | |
.closed | |
.whenComplete(() { | |
if (mounted) { | |
setState(() { | |
_showPersBottomSheetCallBack = _showBottomSheet; | |
}); | |
} | |
}); | |
} | |
void _showModalSheet() { | |
showModalBottomSheet( | |
context: context, | |
builder: (builder) { | |
return new Container( | |
height: 500.0, | |
color: Colors.greenAccent, | |
child: new Center( | |
child: new Text("Hi ModalSheet"), | |
), | |
); | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return new Scaffold( | |
key: _scaffoldKey, | |
appBar: new AppBar( | |
title: new Text("Flutter BottomSheet"), | |
), | |
body: new Padding( | |
padding: const EdgeInsets.all(20.0), | |
child: new Center( | |
child: new Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
new RaisedButton( | |
onPressed: _showPersBottomSheetCallBack, | |
child: new Text("Persistent"), | |
), | |
new Padding( | |
padding: const EdgeInsets.only(top: 10.0), | |
), | |
new RaisedButton( | |
onPressed: _showModalSheet, | |
child: new Text("Modal"), | |
), | |
], | |
)), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment