Skip to content

Commit

Permalink
fix crash issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sachinPramodya committed Nov 11, 2020
1 parent ac9a4ec commit 6182d48
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 69 deletions.
110 changes: 65 additions & 45 deletions lib/page/screen/qr_scan_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class _QrScanScreenState extends State<QrScanScreen> {
final GlobalKey qrKey = GlobalKey(debugLabel: 'QR');
var qrText = "";
QRViewController controller;

bool scanned = false;
@override
void initState() {
super.initState();
Expand All @@ -29,63 +29,83 @@ class _QrScanScreenState extends State<QrScanScreen> {
@override
Widget build(BuildContext context) {
double height = MediaQuery.of(context).size.height;
return Scaffold(
body: Column(
children: <Widget>[
Expanded(
flex: 5,
child: QRView(
key: qrKey,
onQRViewCreated: _onQRViewCreated,
),
),
Row(
children: <Widget>[
Container(
padding: EdgeInsets.all(10),
height: 100,
width: 100,
color: Colors.white,
child: Image.asset(
"assets/images/stay_safe.png",
fit: BoxFit.cover,
),
),
Expanded(
child: Center(
child: Text(
AppLocalizations.of(context).translate("qr_instruct"),
overflow: TextOverflow.ellipsis,
maxLines: 2,
style: TextStyle(color: Colors.black, fontSize: 20),
return scanned == false
? Scaffold(
body: Column(
children: <Widget>[
Expanded(
flex: 5,
child: QRView(
key: qrKey,
onQRViewCreated: _onQRViewCreated,
),
),
)
],
Row(
children: <Widget>[
Container(
padding: EdgeInsets.all(10),
height: 100,
width: 100,
color: Colors.white,
child: Image.asset(
"assets/images/stay_safe.png",
fit: BoxFit.cover,
),
),
Expanded(
child: Center(
child: Text(
AppLocalizations.of(context).translate("qr_instruct"),
overflow: TextOverflow.ellipsis,
maxLines: 2,
style: TextStyle(color: Colors.black, fontSize: 20),
),
),
)
],
)
],
),
)
],
),
);
: Container();
}

void _handleURLButtonPress(BuildContext context, String url) {
// Navigator.push(context,
// MaterialPageRoute(builder: (context) => QrWebviewScreen(url: url)))
// .then((_) {
// _backagain();
// });

Navigator.push(context,
MaterialPageRoute(builder: (context) => QrWebviewScreen(url: url)));
MaterialPageRoute(builder: (context) => QrWebviewScreen(url: url)))
.then((_) {
_backagain();
});
}

void _backagain() {
setState(() {
scanned = false;
controller.resumeCamera();
});
}

void _onQRViewCreated(QRViewController controller) {
print("called");
this.controller = controller;

controller.scannedDataStream.listen((scanData) {
setState(() {
qrText = scanData;
if (scanned == false) {
setState(() {
qrText = scanData;
if (qrText != "") {
scanned = true;

if (qrText != "") {
controller.pauseCamera();
_handleURLButtonPress(context, qrText);
}
});
// controller.resumeCamera();
controller.pauseCamera();
_handleURLButtonPress(context, qrText);
}
});
}
});
}
}
23 changes: 0 additions & 23 deletions lib/page/screen/qr_webview_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,5 @@ class _QrWebviewScreenState extends State<QrWebviewScreen> {
},
javascriptMode: JavascriptMode.unrestricted,
));

// WillPopScope(
// onWillPop: () => _exitApp(context),
// child: Scaffold(
// body: WebView(
// javascriptMode: JavascriptMode.unrestricted,
// initialUrl: widget.url,
// ),
// ),
// );
}

// Future<bool> _exitApp(BuildContext context) async {
// print("cal");
// if (await controllerGlobal.canGoBack()) {
// print("onwill goback");
// controllerGlobal.goBack();
// } else {
// Scaffold.of(context).showSnackBar(
// const SnackBar(content: Text("No back history item")),
// );
// return Future.value(false);
// }
// }
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description: Self tracking app
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.16.0+36
version: 1.17.0+37

environment:
sdk: ">=2.1.0 <3.0.0"
Expand Down

0 comments on commit 6182d48

Please sign in to comment.