|
| 1 | +using System.Collections.Generic; |
| 2 | +using Unity.UIWidgets.material; |
| 3 | +using Unity.UIWidgets.painting; |
| 4 | +using Unity.UIWidgets.ui; |
| 5 | +using Unity.UIWidgets.widgets; |
| 6 | +using DialogUtils = Unity.UIWidgets.material.DialogUtils; |
| 7 | + |
| 8 | +namespace UIWidgetsGallery.gallery { |
| 9 | + public class PersistentBottomSheetDemo : StatefulWidget { |
| 10 | + public const string routeName = "/material/persistent-bottom-sheet"; |
| 11 | + |
| 12 | + public override State createState() { |
| 13 | + return new _PersistentBottomSheetDemoState(); |
| 14 | + } |
| 15 | + } |
| 16 | + |
| 17 | + class _PersistentBottomSheetDemoState : State<PersistentBottomSheetDemo> { |
| 18 | + GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>.key(); |
| 19 | + |
| 20 | + VoidCallback _showBottomSheetCallback; |
| 21 | + |
| 22 | + public override void initState() { |
| 23 | + base.initState(); |
| 24 | + this._showBottomSheetCallback = this._showBottomSheet; |
| 25 | + } |
| 26 | + |
| 27 | + void _showBottomSheet() { |
| 28 | + this.setState(() => { |
| 29 | + // disable the button |
| 30 | + this._showBottomSheetCallback = null; |
| 31 | + }); |
| 32 | + this._scaffoldKey.currentState.showBottomSheet((BuildContext context) => { |
| 33 | + ThemeData themeData = Theme.of(this.context); |
| 34 | + return new Container( |
| 35 | + decoration: new BoxDecoration( |
| 36 | + border: new Border(top: new BorderSide(color: themeData.disabledColor)) |
| 37 | + ), |
| 38 | + child: new Padding( |
| 39 | + padding: EdgeInsets.all(32.0f), |
| 40 | + child: new Text("This is a Material persistent bottom sheet. Drag downwards to dismiss it.", |
| 41 | + textAlign: TextAlign.center, |
| 42 | + style: new TextStyle( |
| 43 | + color: themeData.accentColor, |
| 44 | + fontSize: 24.0f |
| 45 | + ) |
| 46 | + ) |
| 47 | + ) |
| 48 | + ); |
| 49 | + }) |
| 50 | + .closed.Then((value) => { |
| 51 | + if (this.mounted) { |
| 52 | + this.setState(() => { |
| 53 | + // re-enable the button |
| 54 | + this._showBottomSheetCallback = this._showBottomSheet; |
| 55 | + }); |
| 56 | + } |
| 57 | + }); |
| 58 | + } |
| 59 | + |
| 60 | + void _showMessage() { |
| 61 | + DialogUtils.showDialog( |
| 62 | + context: this.context, |
| 63 | + builder: (BuildContext context) => { |
| 64 | + return new AlertDialog( |
| 65 | + content: new Text("You tapped the floating action button."), |
| 66 | + actions: new List<Widget> { |
| 67 | + new FlatButton( |
| 68 | + onPressed: () => { Navigator.pop(context); }, |
| 69 | + child: new Text("OK") |
| 70 | + ) |
| 71 | + } |
| 72 | + ); |
| 73 | + } |
| 74 | + ); |
| 75 | + } |
| 76 | + |
| 77 | + public override Widget build(BuildContext context) { |
| 78 | + return new Scaffold( |
| 79 | + key: this._scaffoldKey, |
| 80 | + appBar: new AppBar( |
| 81 | + title: new Text("Persistent bottom sheet"), |
| 82 | + actions: new List<Widget> { |
| 83 | + new MaterialDemoDocumentationButton(PersistentBottomSheetDemo.routeName) |
| 84 | + } |
| 85 | + ), |
| 86 | + floatingActionButton: new FloatingActionButton( |
| 87 | + onPressed: this._showMessage, |
| 88 | + backgroundColor: Colors.redAccent, |
| 89 | + child: new Icon( |
| 90 | + Icons.add |
| 91 | + ) |
| 92 | + ), |
| 93 | + body: new Center( |
| 94 | + child: new RaisedButton( |
| 95 | + onPressed: this._showBottomSheetCallback, |
| 96 | + child: new Text("SHOW BOTTOM SHEET") |
| 97 | + ) |
| 98 | + ) |
| 99 | + ); |
| 100 | + } |
| 101 | + } |
| 102 | +} |
0 commit comments