Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit 4841a1e

Browse files
author
Yuncong Zhang
committed
Implement persistent bottom sheet demo.
1 parent a9a74cb commit 4841a1e

File tree

3 files changed

+114
-9
lines changed

3 files changed

+114
-9
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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+
}

Samples/UIWidgetsGallery/demo/material/persistent_bottom_sheet_demo.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Samples/UIWidgetsGallery/gallery/demos.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,15 @@ static List<GalleryDemo> _buildGalleryDemos() {
210210
documentationUrl: "https://docs.flutter.io/flutter/material/showModalBottomSheet.html",
211211
buildRoute: (BuildContext context) => new ModalBottomSheetDemo()
212212
),
213-
// new GalleryDemo(
214-
// title: "Bottom sheet: Persistent",
215-
// subtitle: "A bottom sheet that sticks around",
216-
// icon: GalleryIcons.bottom_sheet_persistent,
217-
// category: GalleryDemoCategory._kMaterialComponents,
218-
// routeName: PersistentBottomSheetDemo.routeName,
219-
// documentationUrl: "https://docs.flutter.io/flutter/material/ScaffoldState/showBottomSheet.html",
220-
// buildRoute: (BuildContext context) => PersistentBottomSheetDemo()
221-
// ),
213+
new GalleryDemo(
214+
title: "Bottom sheet: Persistent",
215+
subtitle: "A bottom sheet that sticks around",
216+
icon: GalleryIcons.bottom_sheet_persistent,
217+
category: _kMaterialComponents,
218+
routeName: PersistentBottomSheetDemo.routeName,
219+
documentationUrl: "https://docs.flutter.io/flutter/material/ScaffoldState/showBottomSheet.html",
220+
buildRoute: (BuildContext context) => new PersistentBottomSheetDemo()
221+
),
222222
new GalleryDemo(
223223
title: "Buttons",
224224
subtitle: "Flat, raised, dropdown, and more",

0 commit comments

Comments
 (0)