scanQR function
Implementation
Future<String> scanQR(BuildContext context) async {
// Using Completer to handle the async flow properly
final Completer<String> completer = Completer<String>();
await Navigator.of(context).push(MaterialPageRoute(
builder: (context) {
return scanQRWidget(
onScanned: (result) {
completer.complete(result); // Complete only when we have a confirmed result
},
);
},
));
// Wait for the completer to complete before returning
return await completer.future;
}