parent
653566dd23
commit
08bb332cbb
@ -16,22 +16,18 @@ class ModalBottomSheetDemo extends StatelessWidget {
|
|||||||
return new Scaffold(
|
return new Scaffold(
|
||||||
appBar: new AppBar(title: new Text("Modal Bottom Sheet")),
|
appBar: new AppBar(title: new Text("Modal Bottom Sheet")),
|
||||||
body: new Center(
|
body: new Center(
|
||||||
child: new Container(
|
child: new RaisedButton(
|
||||||
width: 200.0,
|
child: new Text('SHOW BOTTOM SHEET'),
|
||||||
height: 200.0,
|
onPressed: () {
|
||||||
child: new RaisedButton(
|
showModalBottomSheet/*<Null>*/(context: context, builder: (BuildContext context) {
|
||||||
child: new Text('Show the modal bottom sheet', style: textStyle),
|
return new Container(
|
||||||
onPressed: () {
|
child: new Padding(
|
||||||
showModalBottomSheet/*<Null>*/(context: context, builder: (BuildContext context) {
|
padding: const EdgeInsets.all(32.0),
|
||||||
return new Container(
|
child: new Text("This is the modal bottom sheet. Click anywhere to dismiss.", style: textStyle)
|
||||||
child: new Padding(
|
)
|
||||||
padding: const EdgeInsets.all(32.0),
|
);
|
||||||
child: new Text("This is the modal bottom sheet. Click anywhere to dismiss.", style: textStyle)
|
});
|
||||||
)
|
}
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -4,7 +4,13 @@
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class PersistentBottomSheetDemo extends StatelessWidget {
|
class PersistentBottomSheetDemo extends StatefulWidget {
|
||||||
|
@override
|
||||||
|
_PersistentBottomSheetDemoState createState() => new _PersistentBottomSheetDemoState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _PersistentBottomSheetDemoState extends State<PersistentBottomSheetDemo> {
|
||||||
|
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
|
||||||
|
|
||||||
final TextStyle textStyle = new TextStyle(
|
final TextStyle textStyle = new TextStyle(
|
||||||
color: Colors.indigo[400],
|
color: Colors.indigo[400],
|
||||||
@ -12,8 +18,20 @@ class PersistentBottomSheetDemo extends StatelessWidget {
|
|||||||
textAlign: TextAlign.center
|
textAlign: TextAlign.center
|
||||||
);
|
);
|
||||||
|
|
||||||
void showBottomSheet(BuildContext context) {
|
VoidCallback _showBottomSheetCallback;
|
||||||
Scaffold.of(context).showBottomSheet((_) {
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_showBottomSheetCallback = showBottomSheet;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void showBottomSheet() {
|
||||||
|
setState(() { // disable the button
|
||||||
|
_showBottomSheetCallback = null;
|
||||||
|
});
|
||||||
|
_scaffoldKey.currentState.showBottomSheet/*<Null>*/((BuildContext context) {
|
||||||
return new Container(
|
return new Container(
|
||||||
decoration: new BoxDecoration(
|
decoration: new BoxDecoration(
|
||||||
border: new Border(top: new BorderSide(color: Colors.black26))
|
border: new Border(top: new BorderSide(color: Colors.black26))
|
||||||
@ -23,30 +41,28 @@ class PersistentBottomSheetDemo extends StatelessWidget {
|
|||||||
child: new Text("This is a Material persistent bottom sheet. Drag downwards to dismiss it.", style: textStyle)
|
child: new Text("This is a Material persistent bottom sheet. Drag downwards to dismiss it.", style: textStyle)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
})
|
||||||
|
.closed.then((_) {
|
||||||
|
setState(() { // re-enable the button
|
||||||
|
_showBottomSheetCallback = showBottomSheet;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext notUsed) { // Can't find the Scaffold from this context.
|
Widget build(BuildContext context) {
|
||||||
return new Scaffold(
|
return new Scaffold(
|
||||||
|
key: _scaffoldKey,
|
||||||
appBar: new AppBar(title: new Text("Persistent Bottom Sheet")),
|
appBar: new AppBar(title: new Text("Persistent Bottom Sheet")),
|
||||||
floatingActionButton: new FloatingActionButton(
|
floatingActionButton: new FloatingActionButton(
|
||||||
child: new Icon(icon: Icons.add),
|
child: new Icon(icon: Icons.add),
|
||||||
backgroundColor: Colors.redAccent[200]
|
backgroundColor: Colors.redAccent[200]
|
||||||
),
|
),
|
||||||
body: new Builder(
|
body: new Center(
|
||||||
builder: (BuildContext context) {
|
child: new RaisedButton(
|
||||||
return new Center(
|
onPressed: _showBottomSheetCallback,
|
||||||
child: new Container(
|
child: new Text('SHOW BOTTOM SHEET')
|
||||||
width: 200.0,
|
)
|
||||||
height: 200.0,
|
|
||||||
child: new RaisedButton(
|
|
||||||
onPressed: () { showBottomSheet(context); },
|
|
||||||
child: new Text('Show the persistent bottom sheet', style: textStyle)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,16 @@ const String _text2 =
|
|||||||
const String _text3 =
|
const String _text3 =
|
||||||
"By default snackbars automatically disappear after a few seconds ";
|
"By default snackbars automatically disappear after a few seconds ";
|
||||||
|
|
||||||
class SnackBarDemo extends StatelessWidget {
|
class SnackBarDemo extends StatefulWidget {
|
||||||
SnackBarDemo({ Key key }) : super(key: key);
|
SnackBarDemo({ Key key }) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_SnackBarDemoState createState() => new _SnackBarDemoState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SnackBarDemoState extends State<SnackBarDemo> {
|
||||||
|
int _snackBarIndex = 1;
|
||||||
|
|
||||||
Widget buildBody(BuildContext context) {
|
Widget buildBody(BuildContext context) {
|
||||||
return new Padding(
|
return new Padding(
|
||||||
padding: const EdgeInsets.all(24.0),
|
padding: const EdgeInsets.all(24.0),
|
||||||
@ -27,21 +34,24 @@ class SnackBarDemo extends StatelessWidget {
|
|||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
new Text(_text1),
|
new Text(_text1),
|
||||||
new Text(_text2),
|
new Text(_text2),
|
||||||
new RaisedButton(
|
new Center(
|
||||||
child: new Text('Show a SnackBar'),
|
child: new RaisedButton(
|
||||||
onPressed: () {
|
child: new Text('SHOW A SNACKBAR'),
|
||||||
Scaffold.of(context).showSnackBar(new SnackBar(
|
onPressed: () {
|
||||||
content: new Text('This is a SnackBar'),
|
final int thisSnackBarIndex = _snackBarIndex++;
|
||||||
action: new SnackBarAction(
|
Scaffold.of(context).showSnackBar(new SnackBar(
|
||||||
label: 'ACTION',
|
content: new Text('This is SnackBar #$thisSnackBarIndex'),
|
||||||
onPressed: () {
|
action: new SnackBarAction(
|
||||||
Scaffold.of(context).showSnackBar(new SnackBar(
|
label: 'ACTION',
|
||||||
content: new Text("You pressed the SnackBar's Action")
|
onPressed: () {
|
||||||
));
|
Scaffold.of(context).showSnackBar(new SnackBar(
|
||||||
}
|
content: new Text("You pressed SnackBar $thisSnackBarIndex's Action")
|
||||||
)
|
));
|
||||||
));
|
}
|
||||||
}
|
)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
)
|
||||||
),
|
),
|
||||||
new Text(_text3),
|
new Text(_text3),
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user