File tree Expand file tree Collapse file tree 6 files changed +92
-1
lines changed
docs/widget/bulletbox/snackbar Expand file tree Collapse file tree 6 files changed +92
-1
lines changed Original file line number Diff line number Diff line change 1+ ## ** SnackBar**
2+
3+ >
4+ SnackBar 底部快捷提示,类似Toast,会自动隐藏
5+ * 我们并不能直接显示SnackBar,我们可以借助于Scaffold.of(context).showSnackBar()来显示一个SnackBar
6+ * 值得注意的是这个context必须不能是Scaffold节点下的context,因为Scaffold.of()方法需要从Widget树中去找到Scaffold的Context,所以如果直接在Scaffold中使用showSnackBar,需要在外层包括上Builder Widget,这个Builder不做任何的其他操作,只不过把Widget树往下移了一层而已
7+
8+ ### 构造方法
9+ ``` dart
10+ SnackBar({
11+ Key key,
12+ @required this.content,
13+ this.backgroundColor,
14+ this.action,
15+ this.duration = _kSnackBarDisplayDuration,
16+ this.animation,
17+ })
18+ ```
19+
20+ ### 属性介绍
21+ * content: SnackBar要显示的内容
22+ * backgroundColor: SnackBar背景颜色
23+ * action: 用户可以执行的操作
24+ * duration: 显示SnackBar的时间
25+ * animation: SnackBar的显示与隐藏动画
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import 'demo.dart' as Demo;
44
55class Index extends StatefulWidget {
66 static String title = 'BottomSheet' ;
7- static String originCodeUrl = '' ;
7+ static String originCodeUrl = 'https://docs.flutter.io/flutter/material/BottomSheet-class.html ' ;
88 static String mdUrl = 'docs/widget/bulletbox/bottomsheet/index.md' ;
99 @override
1010 _IndexState createState () => _IndexState ();
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import 'package:efox_flutter/store/objects/widget_info.dart';
22import 'simpledialog/index.dart' as SimpleDialog;
33import 'alertdialog/index.dart' as AlertDialog;
44import 'bottomsheet/index.dart' as BottomSheet;
5+ import 'snackbar/index.dart' as SnackBar;
56
67const nameSpaces = '/bulletbox_' ;
78
@@ -20,6 +21,11 @@ List widgets = [
2021 widget: BottomSheet .Index (),
2122 code: 59639 , // card_membership
2223 title: BottomSheet .Index .title
24+ ),
25+ ItemInfo (
26+ widget: SnackBar .Index (),
27+ code: 59670 , // date_range
28+ title: SnackBar .Index .title
2329 )
2430];
2531
Original file line number Diff line number Diff line change 1+ import 'package:flutter/material.dart' ;
2+
3+ class Index extends StatelessWidget {
4+ @override
5+ Widget build (BuildContext context) {
6+ return Scaffold (
7+ appBar: AppBar (title: Text ('SnackBar' ),),
8+ body: Center (
9+ child: Builder (
10+ builder: (BuildContext context) {
11+ return FlatButton (
12+ child: Text ('Open SnackBar' ),
13+ onPressed: () {
14+ Scaffold .of (context).showSnackBar (
15+ SnackBar (
16+ content: Text ('I am SnackBar....' ),
17+ backgroundColor: Theme .of (context).primaryColor,
18+ action: SnackBarAction (
19+ textColor: Colors .white,
20+ label: '撤销' ,
21+ onPressed: (){
22+ },
23+ ),
24+ duration: Duration (seconds: 2 )
25+ )
26+ );
27+ },
28+ );
29+ },
30+ )
31+ ),
32+ );
33+ }
34+ }
Original file line number Diff line number Diff line change 1+ import 'package:flutter/material.dart' ;
2+ import 'package:efox_flutter/components/widgetComp.dart' as WidgetComp;
3+ import 'demo.dart' as Demo;
4+
5+ class Index extends StatefulWidget {
6+ static String title = 'SnackBar' ;
7+ static String originCodeUrl = '' ;
8+ static String mdUrl = 'docs/widget/bulletbox/snackbar/index.md' ;
9+ @override
10+ _IndexState createState () => _IndexState ();
11+ }
12+
13+ class _IndexState extends State <Index > {
14+ @override
15+ Widget build (BuildContext context) {
16+ return WidgetComp .Index (
17+ title: Index .title,
18+ originCodeUrl: Index .originCodeUrl,
19+ mdUrl: Index .mdUrl,
20+ demoChild: < Widget > [
21+ Demo .Index ()
22+ ],
23+ );
24+ }
25+ }
Original file line number Diff line number Diff line change @@ -81,6 +81,7 @@ flutter:
8181 - docs/widget/bulletbox/simpledialog/
8282 - docs/widget/bulletbox/alertdialog/
8383 - docs/widget/bulletbox/bottomsheet/
84+ - docs/widget/bulletbox/snackbar/
8485 - docs/widget/navigator/appbar/
8586 - docs/widget/navigator/scaffold/
8687 # An image asset can refer to one or more resolution-specific "variants", see
You can’t perform that action at this time.
0 commit comments