diff --git a/examples/flutter_gallery/lib/demo/list_demo.dart b/examples/flutter_gallery/lib/demo/list_demo.dart index 5e392d6ca5..ddf95787f0 100644 --- a/examples/flutter_gallery/lib/demo/list_demo.dart +++ b/examples/flutter_gallery/lib/demo/list_demo.dart @@ -10,10 +10,10 @@ class ListDemo extends StatefulWidget { static const String routeName = '/list'; @override - ListDemoState createState() => new ListDemoState(); + _ListDemoState createState() => new _ListDemoState(); } -class ListDemoState extends State { +class _ListDemoState extends State { static final GlobalKey scaffoldKey = new GlobalKey(); PersistentBottomSheetController _bottomSheet; @@ -34,8 +34,8 @@ class ListDemoState extends State { _bottomSheet?.setState(() { }); } - void showConfigurationSheet(BuildContext appContext) { - _bottomSheet = scaffoldKey.currentState.showBottomSheet((BuildContext bottomSheetContext) { + void _showConfigurationSheet() { + final PersistentBottomSheetController bottomSheet = scaffoldKey.currentState.showBottomSheet((BuildContext bottomSheetContext) { return new Container( decoration: new BoxDecoration( border: new Border(top: new BorderSide(color: Colors.black26)), @@ -126,6 +126,18 @@ class ListDemoState extends State { ), ); }); + + setState(() { + _bottomSheet = bottomSheet; + }); + + _bottomSheet.closed.whenComplete(() { + if (mounted) { + setState(() { + _bottomSheet = null; + }); + } + }); } Widget buildListItem(BuildContext context, String item) { @@ -186,7 +198,7 @@ class ListDemoState extends State { new IconButton( icon: new Icon(Icons.more_vert), tooltip: 'Show menu', - onPressed: () { showConfigurationSheet(context); }, + onPressed: _bottomSheet == null ? _showConfigurationSheet : null, ), ], ),