79556469

Date: 2025-04-05 01:55:38
Score: 1
Natty:
Report link

Here's the revised code snippet:

createVehicle(data) {
  progressDialogue(context);
  VehicleService().createVehicle(data).then((onValue) {
    // Navigator.pop(context); // are you sure about this?
    if (onValue['status']) {
      if (onValue['message'] == "success") {
        showToast(
            "${"Successfully".tr} ${widget.edit ? "Update".tr : "Created".tr}");
        Future.delayed(const Duration(seconds: 1), () {
          if (mounted) { // test between mounted and context.mounted if statement
            Navigator.pop(context);
          }
        });
      } else {
        showToast("Already Exist!".tr);
      }
    } else {
      showToast("Something Went Wrong!".tr);
    }
  });
}

You may probably notice // Navigator.pop(context); // are you sure about this?. It seemed you overlooked that Navigator.pop(context); instance before if (onValue['status']) { statement. So if this statement if (onValue['message'] == "success") { is true.

Most likely causes you to encounter the exception:

navigation problem 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 5859 pos 12: '!_debugLocked': is not true

Therefore, I advise you to comment out the first instance of Navigator.pop(context); before if (onValue['status']) { in the meantime to check if it resolves your issue, if it resolved your issue, then feel free to remove that in your code.

Lastly, this is optional depending on your use case or testing:

Future.delayed(const Duration(milliseconds: 1000), () {
  // your navigation here
});

Watch this video to learn more: Resolving !_debugLocked is not true Error in Flutter Navigation.

Reasons:
  • Blacklisted phrase (1): to comment
  • Blacklisted phrase (1): this video
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: DevQt