I am submitting a form to the server and the form is being sent successfully and result code being returned but for some wierd reason my showsavingdialog function is stuck at saving and doesn't proceed to show the message Form submitted successfuly. What am i doing wrong?
create entry
Future<void> createEntry(
String id,
String formName,
String dataContent,
String dateCreated,
String dateUpdated,
String userLocation,
String imeI,
String updatedBy,
bool isNew) async {
debugPrint("createEntry web called");
String apiUrl = hostUrl + "entry";
debugPrint("sending form to $apiUrl");
if (isNew) {
// creating new record
try {
Map<String, dynamic> data = {
"id": id,
"formName": formName,
"dateCreated": dateCreated,
"dataContent": dataContent,
"dateUpdated": dateUpdated,
"userLocation": "userLocation",
"imeI": "imeI",
"updatedBy": updatedBy,
"synced": true
};
var resp = await Dio().post(apiUrl, data: data);
int result = resp.statusCode;
if (result == 201) {
_showAlertDialog("Success", "Your form has been saved");
} else {
_showAlertDialog(
"Error", "Your form could not be saved due to an error");
}
} on DioError catch (e) {
debugPrint("$e");
debugPrint(e.message);
_showAlertDialog(
"Error", "Your form could not be saved due to an error");
} finally {
saving = false; // change save button back to "save"
}
}
saving function
void _save() async {
debugPrint("_save() called");
saving = true; // switch save button to display "saving..."
setFacility();
isFormValid();
_showSavingDialog();
String uuid = this.dbForm.id == null ? Uuid().v4() : this.dbForm.id;
String op = this.dbForm.id == null ? "insert" : "update";
// create variables, then store in server
final String id = uuid;
final String formName = template.form_name;
final String dateCreated = DateTime.now().toString();
final String dateUpdated = DateTime.now().toString();
final String dataContent = encodeResponse();
final String updatedBy = username;
final String userLocation = "isAndroid";
final String imeI = "isAndroid" ;
// List<Future> futures = <Future>[];
if (op == "insert") {
await createEntry(id, formName, dataContent, dateCreated, dateUpdated,
userLocation, imeI, updatedBy, true);
} else {
await createEntry(id, formName, dataContent, dateCreated, dateUpdated,
userLocation, imeI, updatedBy, false);
}
}
the show saving dialog
void _showSavingDialog() {
AlertDialog saveDialog = AlertDialog(
content: Row(
children: <Widget>[
Padding(
child: SizedBox(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Colors.black54),
),
height: 15.0,
width: 15.0),
padding: EdgeInsets.only(left: 15.0),
),
Padding(
child: Text(
"Saving...",
style: TextStyle(color: Colors.black54),
textAlign: TextAlign.center,
),
padding: EdgeInsets.all(15.0),
),
],
));
showDialog(
context: context,
builder: (_) => saveDialog,
barrierDismissible: false);
}
I always get an error
Error: This widget has been unmounted, so the State no longer has a context (and should be considered defunct). Consider canceling any active work during "dispose" or using the "mounted" getter to determine if the State is still active.
and the saving dialog stuck at saving, Any help will be appreciated