标签:lis package cond rac new second ott ide sam
注意:
build(BuildContext context)在 Scaffold.of(context)之前时,会报错,解决办法:
通过build widget来解决,如下代码。
import ‘package:flutter/material.dart‘; main() => runApp(MaterialApp( home: MyHome(), )); class MyHome extends StatefulWidget { @override State<StatefulWidget> createState() { // TODO: implement createState return MyHomePageState(); } } class MyHomePageState extends State<MyHome> { Widget sdtSnack = SnackBar(content: Text(‘sdt‘)); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(‘BottomNavigationBar Sample‘), ), body: Center( child: new ListView( children: <Widget>[ new FlatButton( onPressed: (){ Scaffold.of(context).showSnackBar(sdtSnack); }, child: new Text(‘我是按钮‘), ), Builder(builder: (BuildContext context) { return new Center( child: new GestureDetector( onTap: () { final mySnackBar = SnackBar( content: new Text(‘我是SnackBar‘), duration: Duration(seconds: 4), action: new SnackBarAction( label: ‘我是scackbar按钮‘, onPressed: () { print(‘点击了snackbar按钮‘); }), ); Scaffold.of(context).showSnackBar(mySnackBar); }, child: new Text(‘点我显示SnackBar‘), ), ); }), ], ), ), ); } }
标签:lis package cond rac new second ott ide sam
原文地址:https://www.cnblogs.com/pythonClub/p/10799459.html