'Flutter how to show a Dialog infront of a camera (FlutterBarcodeScanner)
Im creating an app that will allow the user to scan barcodes continuously until they choose to stop. For each barcode the user scans i need to be able to call an API to check if the API has information about that barcode. In the case where the API doesnt have information about a barcode i would like to show a Dialog box to allow the user to enter information about the product they just scanned.
Im using the FlutterBarcodeScanner package to scan barcodes continuously which works perfectly. However in the callback function thats triggered when a barcode is scanned i want to show a dialog box but it is shown on the previous screen i was on before opening the camera with the FlutterBarcodeScanner package. I would instead like the Dialog to show ontop of the camera.
To show the dialog im using a global key thats holds the context. Given that the dialog is showing on the previous screen its almost like the camera screen has no context that i can access that will allow me to show a dialog within the cameras context, not the previous screens context.
Just to note i have tried navigatorKey.currentContext aswell but unfortunately makes no difference
class CustomFloatingActionButtonController {
void search() {
print("search");
}
Future<void> barcode() async {
FlutterBarcodeScanner.getBarcodeStreamReceiver(
'#00000000', 'Finish', true, ScanMode.BARCODE)!
.listen(
(barcode) {
//Callback for when a barcode is scanned
_showDialog(barcode);
},
);
}
void _showDialog(String barcode) {
VoidCallback continueCallBack = () => { //Callback for Dialog not barcode scanner
Navigator.of(navigatorKey.currentContext!).pop(),
// code on continue comes here
};
ErrorDialogBox alert = ErrorDialogBox.rawTextError(barcode); //Custom alert box works fine
just shows in wrong context
showDialog(
context: navigatorKey.currentState!.overlay!.context,
//Have also tried navigatorKey.currentContext it seems to make no difference
builder: (_) {
return alert;
},
);
}
}
Any help or suggestions are much appreciated. Thanks in advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
