【发布时间】:2018-03-15 19:50:03
【问题描述】:
我开始关注 Firebase CodeLab,之后对其进行了修改和添加。我正在尝试使用 Snackbar,但没有成功。
class ChatScreenState extends State<ChatScreen> {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Teapot"),
elevation:
Theme.of(context).platform == TargetPlatform.iOS ? 0.0 : 4.0),
body: new Container(
child: new Column(
children: <Widget>[
new Flexible(
// stuff
),
new Divider(height: 1.0),
new Container(
decoration: new BoxDecoration(color: Theme
.of(context).cardColor),
//call ---> child: _buildTextComposer(),
),
],
),
),
);
}
Widget _buildTextComposer() {
return new IconTheme(
data: new IconThemeData(color: Theme.of(context).accentColor),
child: new Container(
margin: const EdgeInsets.symmetric(horizontal: 8.0),
child: new Row(
children: <Widget>[
new Container(
margin: new EdgeInsets.symmetric(horizontal: 4.0),
child: new IconButton(
icon: new Icon(Icons.photo_camera),
onPressed: () async {
await _ensureLoggedIn();
File imageFile = await ImagePicker.pickImage();
int random = new Random().nextInt(100000);
StorageReference ref =
FirebaseStorage.instance.ref().child("image_$random.jpg");
StorageUploadTask uploadTask = ref.put(imageFile);
Uri downloadUrl = (await uploadTask.future).downloadUrl;
_sendMessage(imageUrl: downloadUrl.toString());
//bonk! ---> Scaffold.of(context).showSnackBar(new SnackBar(
content: new Text("Image Sent"),
));
}
),
),
// more stuff
当它尝试显示距底部约 6 行的SnackBar 时(请参阅bonk! --->),我收到一条错误消息,指出上下文中没有脚手架。我对此感到困惑,因为 _buildTextComposer 是从 Scaffold 内部(参见第 4 行)调用的(参见 call -->)。
我做错了什么?
【问题讨论】:
标签: flutter