我正在开发一个关于Flutter 的项目.但我在我的添加按钮主页上遇到了这样的错误.我如何解决这个问题?一旦我通过纠正空安全错误添加了一个产品,它就被修复了,但现在还没有修复.
GestureDetector(
onTap: () async {
if (_newProductGroup.text != "" && _newProductGroup.text != null) {
try {
final DocumentSnapshot<Map<String, dynamic>>
_doc = await _firestore
.collection("utils")
.doc("productGroups")
.get();
final List<dynamic> _tempList =
_doc.data()!['list'] as List<dynamic>;
if (_tempList.contains(_newProductGroup.text)) {
showTextToast("Bu alan daha önce oluşturuldu");
} else {
_tempList.add(_newProductGroup.text);
_firestore
.collection('utils')
.doc("productGroups")
.update({'list': _tempList});
showTextToast("Başarıyla Eklendi");
}
} catch (e) {
showTextToast("An Error Occured!");
}
// ignore: use_build_context_synchronously
Navigator.of(context).pop();
_newProductGroup.text = "";
} else {
showTextToast("Boş Bırakmayın!");
}
},
Expanded(
child: StreamBuilder(
stream:
_firestore.collection("utils").snapshots(),
builder: (
BuildContext context,
AsyncSnapshot<
QuerySnapshot<Map<String, dynamic>>>
snapshot,
) {
if (snapshot.hasData) {
final List<dynamic> _productGroups =
(snapshot.data!.docs[0].data()['list'] ?? [])
as List<dynamic>;
_productGroups.sort();
return GridView.builder(
gridDelegate:
const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 2,
crossAxisSpacing: 20,
mainAxisSpacing: 20,
),
itemCount: _productGroups.length,
itemBuilder: (context, index) {
return ProductGroupCard(
name: _productGroups[index] as String,
key: UniqueKey(),
);
},
);
我现在已经修复了红色屏幕,但无法添加产品名称.
添加按钮
点击后错误
DB