@@ -9,7 +9,6 @@ import '../routers/routers.dart';
99import '../components/markdown.dart' ;
1010import '../model/collection.dart' ;
1111import '../widgets/index.dart' ;
12- import 'package:fluttertoast/fluttertoast.dart' ;
1312import '../event/event_bus.dart' ;
1413import '../event/event_model.dart' ;
1514import 'dart:core' ;
@@ -27,8 +26,7 @@ class WidgetDemo extends StatefulWidget {
2726 @required this .contentList,
2827 @required this .codeUrl,
2928 @required this .docUrl,
30- this .bottomNaviBar
31- })
29+ this .bottomNaviBar})
3230 : super (key: key);
3331
3432 _WidgetDemoState createState () => _WidgetDemoState ();
@@ -40,17 +38,7 @@ class _WidgetDemoState extends State<WidgetDemo> {
4038 var _collectionIcons;
4139 List widgetDemosList = new WidgetDemoList ().getDemos ();
4240 String _router = '' ;
43-
44- void showInSnackBar (String value) {
45- Fluttertoast .showToast (
46- msg: value,
47- toastLength: Toast .LENGTH_SHORT ,
48- gravity: ToastGravity .CENTER ,
49- timeInSecForIos: 1 ,
50- backgroundColor: Colors .grey,
51- textColor: Colors .white);
52- }
53-
41+ final GlobalKey <ScaffoldState > _scaffoldKey = GlobalKey <ScaffoldState >();
5442
5543 List <Widget > _buildContent () {
5644 List <Widget > _list = [
@@ -99,8 +87,8 @@ class _WidgetDemoState extends State<WidgetDemo> {
9987 setState (() {
10088 _hasCollected = false ;
10189 });
102- showInSnackBar ( '已取消收藏' );
103-
90+ _scaffoldKey.currentState
91+ . showSnackBar ( SnackBar (content : Text ( '已取消收藏' )));
10492 if (ApplicationEvent .event != null ) {
10593 ApplicationEvent .event
10694 .fire (CollectionEvent (widget.title, _router, true ));
@@ -124,19 +112,21 @@ class _WidgetDemoState extends State<WidgetDemo> {
124112 .fire (CollectionEvent (widget.title, _router, false ));
125113 }
126114
127- showInSnackBar ('收藏成功' );
115+ _scaffoldKey.currentState
116+ .showSnackBar (SnackBar (content: Text ('收藏成功' )));
128117 }
129118 });
130119 }
131120 }
132121
133- void _selectValue (value){
134- if (value == 'doc' ){
122+ void _selectValue (value) {
123+ if (value == 'doc' ) {
135124 // _launchURL(widget.docUrl);
136- Application .router.navigateTo (context, '${Routes .webViewPage }?title=${Uri .encodeComponent (widget .title )} Doc&&url=${Uri .encodeComponent (widget .docUrl )}' );
137- }else if (value == 'code' ){
138- Application .router.navigateTo (context, '${Routes .codeView }?filePath=${Uri .encodeComponent (widget .codeUrl )}' );
139-
125+ Application .router.navigateTo (context,
126+ '${Routes .webViewPage }?title=${Uri .encodeComponent (widget .title )} Doc&&url=${Uri .encodeComponent (widget .docUrl )}' );
127+ } else if (value == 'code' ) {
128+ Application .router.navigateTo (context,
129+ '${Routes .codeView }?filePath=${Uri .encodeComponent (widget .codeUrl )}' );
140130 }
141131 }
142132
@@ -148,57 +138,63 @@ class _WidgetDemoState extends State<WidgetDemo> {
148138 _collectionIcons = Icons .favorite_border;
149139 }
150140 return Scaffold (
151- appBar: AppBar (
152- title: Text (widget.title),
153- actions: < Widget > [
154- new IconButton (
155- tooltip: 'goBack home' ,
156- onPressed: () {
157- Navigator .popUntil (context, ModalRoute .withName ('/home' ));
158- },
159- icon: Icon (Icons .home),
160- ),
161- new IconButton (
162- tooltip: 'collection' ,
163- onPressed: _getCollection,
164- icon: Icon (_collectionIcons),
165- ),
166- PopupMenuButton <String >(
167- onSelected: _selectValue,
168- itemBuilder: (BuildContext context) => < PopupMenuEntry <String >> [
169- const PopupMenuItem <String >(
170- value: 'doc' ,
171- child: ListTile (
172- leading: Icon (Icons .library_books,size: 22.0 ,),
173- title: Text ('查看文档' ),
141+ key: _scaffoldKey,
142+ appBar: AppBar (
143+ title: Text (widget.title),
144+ actions: < Widget > [
145+ new IconButton (
146+ tooltip: 'goBack home' ,
147+ onPressed: () {
148+ Navigator .popUntil (context, ModalRoute .withName ('/home' ));
149+ },
150+ icon: Icon (Icons .home),
151+ ),
152+ new IconButton (
153+ tooltip: 'collection' ,
154+ onPressed: _getCollection,
155+ icon: Icon (_collectionIcons),
156+ ),
157+ PopupMenuButton <String >(
158+ onSelected: _selectValue,
159+ itemBuilder: (BuildContext context) => < PopupMenuEntry <String >> [
160+ const PopupMenuItem <String >(
161+ value: 'doc' ,
162+ child: ListTile (
163+ leading: Icon (
164+ Icons .library_books,
165+ size: 22.0 ,
166+ ),
167+ title: Text ('查看文档' ),
168+ ),
174169 ),
175- ),
176- const PopupMenuDivider (),
177- const PopupMenuItem <String >(
178- value: 'code' ,
179- child: ListTile (
180- leading: Icon (Icons .code,size: 22.0 ,),
181- title: Text ('查看Demo' ),
170+ const PopupMenuDivider (),
171+ const PopupMenuItem <String >(
172+ value: 'code' ,
173+ child: ListTile (
174+ leading: Icon (
175+ Icons .code,
176+ size: 22.0 ,
177+ ),
178+ title: Text ('查看Demo' ),
179+ ),
182180 ),
183- ),
184- ],
185- ),
186- ],
187- ),
188- body: Container (
189- padding: const EdgeInsets .symmetric (vertical: 10.0 , horizontal: 15.0 ),
190- child: ListView (
191- shrinkWrap: true ,
192- padding: const EdgeInsets .all (0.0 ),
193- children: < Widget > [
194- Column (
195- children: _buildContent (),
181+ ],
196182 ),
197183 ],
198184 ),
199- ),
200- bottomNavigationBar: (widget.bottomNaviBar is Widget ) ? widget
201- .bottomNaviBar : null
202- );
185+ body: Container (
186+ padding: const EdgeInsets .symmetric (vertical: 10.0 , horizontal: 15.0 ),
187+ child: ListView (
188+ shrinkWrap: true ,
189+ padding: const EdgeInsets .all (0.0 ),
190+ children: < Widget > [
191+ Column (
192+ children: _buildContent (),
193+ ),
194+ ],
195+ ),
196+ ),
197+ bottomNavigationBar:
198+ (widget.bottomNaviBar is Widget ) ? widget.bottomNaviBar : null );
203199 }
204200}
0 commit comments