Closed caktoy closed 5 years ago
Cancel button listener is not available now. Is there any special requirement for a listener?
Would you mind to add it later? Actually I didn't think that is have any special requirement for that.
Ok. I'll figure out scenarios that would be helpful to get the listener, will update you on this later.
Ok, thank you, I'll wait it
I'd like to be able to specify the cancel event. The reason is that I want the scanner to load and start scanning when the page loads, as such I'd like for the user to be able to cancel the scanning and take them back to either a blank page where they can start the scanner again or pop them back to the page they came from.
The cancel button is already there in barcode scanning screen, so if a user needs to stop the scanning, user can do it by clicking on cancel button.
Is there also a way to programmatically cancel scanning? Sorry I haven't had a chance to look at the code.
This is a simple code I used:
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String barcodeScanRes;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
barcodeScanRes = await FlutterBarcodeScanner.scanBarcode("#9dff00", "Cancel", true);
} on PlatformException {
barcodeScanRes = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
Navigator.pop(_scaffoldKey.currentContext);
if (barcodeScanRes.isNotEmpty)
Navigator.of(_scaffoldKey.currentContext).push(MaterialPageRoute(builder: (BuildContext context) => new DetailScreen()));
}
With that code, I just close current screen that contain scanner instance first, if there is any result after scanning process, then push to another screen I want.
Is that solved your query?
How to override 'Cancel' button action? Any suggestions?