@override
Widget build(BuildContext context) {
return WillPopScope(
child: SafeArea(
child: Scaffold(
backgroundColor: Colors.transparent,
// appBar: AppBar(
// title: Text('Future Demo Page'),
// ),
body: ProgressHUD(
inAsyncCall: isLoading,
child: Stack(
children: <Widget>[
getBarcodeData(),
],
),
)),
),
onWillPop: onBackPress);
}
Future<bool> onBackPress() {
Navigator.pop(context);
String imageUrl = StorageUtil.getString('imageurl');
String strBussName = StorageUtil.getString('buss_name');
String strName = StorageUtil.getString('name');
Navigator.pop(context);
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => MainActivity(imageUrl, strName, strBussName)));
return null;
}
getBarcodeData() async {
try {
final qrcoder = await FlutterBarcodeScanner.scanBarcode(
'#ff6666', 'Cancel', true, ScanMode.QR);
if (!mounted) return;
this.barcodeScanner = qrcoder;
if (barcodeScanner.isNotEmpty) {
getGoodsData(barcodeScanner);
}
} catch (error) {
barcodeScanner = 'Falied to get Platform Version';
}
return barcodeScanner;
}
I am implementing barcode and QR code scanning in my application. Whenever i am scanning i have to get the data from QR code/barcode later i want to send that data with API. Once the API is successfully called after getting response i want to show some dialog. The issue is after scanning page is closing and not showing dialog please help me to achieve.
Note: After scanning page should not close need to show dialog
Thanks in Advance!
CodePudding user response:
@override
Widget build(BuildContext context) {
return WillPopScope(
child: SafeArea(
child: Scaffold(
backgroundColor: Colors.transparent,
// appBar: AppBar(
// title: Text('Future Demo Page'),
// ),
body: ProgressHUD(
inAsyncCall: isLoading,
child: Stack(
children: <Widget>[
getBarcodeData(),
],
),
)),
),
onWillPop: onBackPress);
}
Future<bool> onBackPress() {
Navigator.pop(context);
String imageUrl = StorageUtil.getString('imageurl');
String strBussName = StorageUtil.getString('buss_name');
String strName = StorageUtil.getString('name');
Navigator.pop(context);
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => MainActivity(imageUrl, strName, strBussName)));
return null;
}
getBarcodeData() async {
try {
final qrcoder = await FlutterBarcodeScanner.scanBarcode(
'#ff6666', 'Cancel', true, ScanMode.QR);
if (!mounted) return;
this.barcodeScanner = qrcoder;
if (barcodeScanner.isNotEmpty) {
getGoodsData(barcodeScanner);
showDialog(
context: context,
builder: (context) => new AlertDialog(
title: new Text(
'Notice',
style: TextStyle(color: Colors.blueGrey),
),
content: Text(
'Here is your dialogue...',
style: TextStyle(color: Colors.black),
),
actions: <Widget>[
new TextButton(
onPressed: () {
//Todo add any thing you want
},
child: new Text('OK'),
),
],
),
);
}
} catch (error) {
barcodeScanner = 'Falied to get Platform Version';
}
return barcodeScanner;
}
If the above code worked fine then all you need is just showing the dialogue as the above. Add more info to make the question useful for other people too.
CodePudding user response:
it could be because you are calling Navigator.pop(context); twice in onBackPress()?
Not sure how deep in the app this is taking place, but that might be the first place to check.