每次尝试重复该项目时,我都试图应用对话框警报,但是当我进行测试时,它最终给出了此错误,是否有人对如何解决此问题有任何提示?
void SalvarMensagem() async {
// select id_armarios from armarios where numero_serie = '$_numeroSerie'
this._status = _status;
_numeroSerie = _status.substring(48, 80);
final QuerySnapshot result = await Future.value(Firestore.instance
.collection("lockers")
.where("numero_serie", isEqualTo: "$_numeroSerie")
.limit(1)
.getDocuments());
final List<DocumentSnapshot> documents = result.documents;
if (documents.length == 1) {
duplicado(context);
} else {
await Firestore.instance
.collection("lockers")
.document()
.setData({"numero_serie": _numeroSerie});
}
}
duplicado(BuildContext context){
Alert(
context: context,
type: AlertType.error,
title: "QR Code já cadastrado",
buttons: [
DialogButton(
child: Text(
"OK",
style: TextStyle(color: Colors.white, fontSize: 20),
),
onPressed: () => Navigator.pop(context),
color: Colors.lightBlueAccent,
width: 120,
)
],
).show();
}
错误:
E / flutter(9129):[错误:flutter / lib / ui / ui_dart_state.cc(148)] 未处理的异常:'package:flutter / src / widgets / localizations.dart': 断言失败:446行pos 12:'context!= null':不正确。
答案 0 :(得分:0)
duplicate(context, title, content) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: new Text(
title,
),
content: Padding(
padding: const EdgeInsets.all(8.0),
child: new Text(
content,
),
),
actions: <Widget>[
new FlatButton(
child: new Text(
"OK",
style: TextStyle(color: Colors.white),
),
onPressed: () {
Navigator.of(context).pop();
},
color: Colors.lightBlueAccent,
),
],
);
},
);
}
更改警报功能并用duplicate(context,"QR Code já cadastrado","The content you wanted or delete it")
调用它应该没问题。您可以使用功能参数更改标题和内容。