firebase - 没有为“BuildContext”类型定义方法“showSnackBar”
问题描述
在这里,我创建了一个 DropdownItemMenu,它从 firebase 集合中获取元素,但它显示了一个错误
没有为“BuildContext”类型定义方法“showSnackBar”
Container(
margin: EdgeInsets.only(left: 16, right: 16),
height: MediaQuery.of(context).size.height * 0.10,
child: Card(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: DropdownButton<String>(
isExpanded: false,
style: TextStyle(
fontSize: 14, color: Colors.blueGrey),
icon: const Icon(Icons.keyboard_arrow_down),
underline: Container(color: Colors.transparent),
onChanged: (serieValue) {
final snackBar = SnackBar(
content: Text(
'Série selectionnée est $serieValue',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14,
color: Color(0xff11b719)),
));
Scaffold.of(context.showSnackBar(snackBar));
setState(() {
selectedIndexSerie = serieValue;
});
},
value: selectedIndexSerie,
hint: Text(
'Selectionner une série',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14,
color: Color(0xff11b719)),
),
items: series,
),
),
),
);
解决方案
你放错了')' -->
Scaffold.of(context).showSnackBar(snackBar);
此外,不推荐使用 showSnackBar,请考虑使用 ScaffoldMessenger
ScaffoldMessenger.of(context).showSnackBar(snackBar);
推荐阅读
- c# - 将表格复制到 WPF RichTextBox 中丢失边框
- pipe - 后台进程,使用 stdin 管道连接到父 shell 脚本中的 fd 3
- vue.js - 如何将 Vuetify 用于 Keycloak 登录主题
- javascript - FullCalendar v5 自定义多日事件的字体和背景颜色
- c++ - 什么时候在 C/C++ 中分配静态内存?在编译时还是在程序运行的最开始?
- r - 从另一个数据集中填充多列缺失数据
- api - 使用 github api 上的 web 服务等请求获取包的最新发布版本
- java - Webrtc:onIceConnectionChange和onConnectionChange有什么区别
- python - 使用深度学习改进多标签文本分类问题的结果
- c++ - 作为函数声明中的类型名称的概念在 C++20 中是否有效?