1
I’m trying to apply a dialog alert every time the item is duplicated but when I do the test it ends up giving this error, someone has some hint how to fix it ?
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();
}
Error:
E/flutter ( 9129): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: 'package:flutter/src/widgets/localizations.Dart': Failed assertion: line 446 pos 12: 'context != null': is not true.
Where it comes from
context
inSalvarMensagem
?– rubStackOverflow
comes from the duplicate function(title: "QR Code already registered")
– Jackson Felipe Magnabosco
The error message informs that
context
is null (null), I believecontext
must come fromwidget
what callSalvarMensagem
and then must be passed toduplicado
– rubStackOverflow