class SnackBarDemo extends StatefulWidget {
@override
_SnackBarDemoState createState() => _SnackBarDemoState();
}
class _SnackBarDemoState extends State<SnackBarDemo> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('SnackBarDemo'),
),
body: Container(
padding: EdgeInsets.all(16),
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SnackButton(),
],
),
),
),
);
}
}
class SnackButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return FlatButton(
child: Text('Open SnackBar'),
onPressed: (){
Scaffold.of(context).showSnackBar(
SnackBar(
content: Text('Processing...'),
action: SnackBarAction(
label: 'OK',
onPressed: (){},
),
)
);
},
);
}
}
image.png
网友评论