forked from simplezhli/flutter_deer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2aa0681
commit 419fe19
Showing
9 changed files
with
168 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
|
||
|
||
import 'dart:io'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_deer/routers/fluro_navigator.dart'; | ||
import 'package:qr_code_scanner/qr_code_scanner.dart'; | ||
|
||
class QrCodeScannerPage extends StatefulWidget { | ||
|
||
const QrCodeScannerPage({Key key}) : super(key: key); | ||
|
||
@override | ||
_QrCodeScannerPageState createState() => _QrCodeScannerPageState(); | ||
} | ||
|
||
class _QrCodeScannerPageState extends State<QrCodeScannerPage> { | ||
final GlobalKey qrKey = GlobalKey(debugLabel: 'QR'); | ||
Barcode result; | ||
QRViewController controller; | ||
|
||
/// In order to get hot reload to work we need to pause the camera if the platform | ||
/// is android, or resume the camera if the platform is iOS. | ||
@override | ||
void reassemble() { | ||
super.reassemble(); | ||
if (Platform.isAndroid) { | ||
controller.pauseCamera(); | ||
} else if (Platform.isIOS) { | ||
controller.resumeCamera(); | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final scanArea = (MediaQuery.of(context).size.width < 400 || | ||
MediaQuery.of(context).size.height < 400) | ||
? 250.0 | ||
: 300.0; | ||
return Scaffold( | ||
body: Stack( | ||
children: <Widget>[ | ||
Positioned.fill( | ||
child: QRView( | ||
key: qrKey, | ||
onQRViewCreated: _onQRViewCreated, | ||
overlay: QrScannerOverlayShape( | ||
borderColor: Colors.red, | ||
borderRadius: 10, | ||
borderLength: 20, | ||
borderWidth: 5, | ||
cutOutSize: scanArea, | ||
), | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
|
||
void _onQRViewCreated(QRViewController controller) { | ||
this.controller = controller; | ||
controller.scannedDataStream.listen((scanData) { | ||
NavigatorUtils.goBackWithParams(context, result.code); | ||
}); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
controller?.dispose(); | ||
super.dispose(); | ||
} | ||
} |
Oops, something went wrong.