From 9336171a2e738f37520aba77f715e95b219eecb4 Mon Sep 17 00:00:00 2001 From: Julian Steenbakker Date: Mon, 11 Jan 2021 10:22:47 +0100 Subject: [PATCH] Release of v0.3.0 --- CHANGELOG.md | 17 ++++++- example/README.md | 113 ++++++++++++++++++---------------------------- pubspec.yaml | 2 +- 3 files changed, 61 insertions(+), 71 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b913faf..450da96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,18 @@ +## 0.3.0 +#### Breaking change +Its not necessary anymore to wrap the QRView in a SizeChangedLayoutNotifier because this is handled inside the plugin. +#### New Features +* Added possibility to set allowed barcodes. (#135) +* Added possibility to check what features are supported by device. (hasFlash, hasBackCamera, hasFrontCamera) (#135) +* Added possibility to check if flash is on. (#135) +* Added possibility to check which camera is active. (#135) +* All functions are now async so you can await them. (#135) + +See the updated example on how to implement these features. +#### Bug fixes +* Fixed permission handling in Android. +* Native functions now returns results so exceptions can be thrown when an error occurs. + ## 0.2.1 * Fixed critical bug where scanner wouldn't open when no scan overlay was configured. @@ -29,7 +44,7 @@ ## 0.0.12 * Add optional parameter to use a camera overlay. -* Simplfiy controller, expose scanDataStream. +* Simplify controller, expose scanDataStream. * Fix for Android flash toggle. * Add ability to pause/resume the camera. * Thanks! to Luis Thein for all the above contributions. diff --git a/example/README.md b/example/README.md index 20d5579..d389eb9 100644 --- a/example/README.md +++ b/example/README.md @@ -21,16 +21,14 @@ Demonstrates how to use the qr_code_scanner plugin. ## Example: ```dart +import 'dart:io'; + +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:qr_code_scanner/qr_code_scanner.dart'; void main() => runApp(MaterialApp(home: QRViewExample())); -const flashOn = 'FLASH ON'; -const flashOff = 'FLASH OFF'; -const frontCamera = 'FRONT CAMERA'; -const backCamera = 'BACK CAMERA'; - class QRViewExample extends StatefulWidget { const QRViewExample({ Key key, @@ -42,8 +40,6 @@ class QRViewExample extends StatefulWidget { class _QRViewExampleState extends State { Barcode result; - var flashState = flashOn; - var cameraState = frontCamera; QRViewController controller; final GlobalKey qrKey = GlobalKey(debugLabel: 'QR'); @@ -84,44 +80,33 @@ class _QRViewExampleState extends State { Container( margin: EdgeInsets.all(8), child: RaisedButton( - onPressed: () { - if (controller != null) { - controller.toggleFlash(); - if (_isFlashOn(flashState)) { - setState(() { - flashState = flashOff; - }); - } else { - setState(() { - flashState = flashOn; - }); - } - } - }, - child: - Text(flashState, style: TextStyle(fontSize: 20)), - ), + onPressed: () => setState(() { + controller?.toggleFlash(); + }), + child: FutureBuilder( + future: controller?.getFlashStatus(), + builder: (context, snapshot) { + return Text('Flash: ${snapshot.data}'); + }, + )), ), Container( margin: EdgeInsets.all(8), child: RaisedButton( - onPressed: () { - if (controller != null) { - controller.flipCamera(); - if (_isBackCamera(cameraState)) { - setState(() { - cameraState = frontCamera; - }); - } else { - setState(() { - cameraState = backCamera; - }); - } - } - }, - child: - Text(cameraState, style: TextStyle(fontSize: 20)), - ), + onPressed: () => setState(() { + controller?.flipCamera(); + }), + child: FutureBuilder( + future: controller?.getCameraInfo(), + builder: (context, snapshot) { + if (snapshot.data != null) { + return Text( + 'Camera facing ${describeEnum(snapshot.data)}'); + } else { + return Text('loading'); + } + }, + )), ) ], ), @@ -158,14 +143,6 @@ class _QRViewExampleState extends State { ); } - bool _isFlashOn(String current) { - return flashOn == current; - } - - bool _isBackCamera(String current) { - return backCamera == current; - } - Widget _buildQrView(BuildContext context) { // For this example we check how width or tall the device is and change the scanArea and overlay accordingly. var scanArea = (MediaQuery.of(context).size.width < 400 || @@ -174,29 +151,27 @@ class _QRViewExampleState extends State { : 300.0; // To ensure the Scanner view is properly sizes after rotation // we need to listen for Flutter SizeChanged notification and update controller - return NotificationListener( - onNotification: (notification) { - Future.microtask( - () => controller?.updateDimensions(qrKey, scanArea: scanArea)); - return false; - }, - child: SizeChangedLayoutNotifier( - key: const Key('qr-size-notifier'), - child: QRView( - key: qrKey, - onQRViewCreated: _onQRViewCreated, - overlay: QrScannerOverlayShape( - borderColor: Colors.red, - borderRadius: 10, - borderLength: 30, - borderWidth: 10, - cutOutSize: scanArea, - ), - ))); + return QRView( + key: qrKey, + // You can choose between CameraFacing.front or CameraFacing.back. Defaults to CameraFacing.back + cameraFacing: CameraFacing.front, + onQRViewCreated: _onQRViewCreated, + // Choose formats you want to scan. Defaults to all formats. + formatsAllowed: [BarcodeFormat.qrcode], + overlay: QrScannerOverlayShape( + borderColor: Colors.red, + borderRadius: 10, + borderLength: 30, + borderWidth: 10, + cutOutSize: scanArea, + ), + ); } void _onQRViewCreated(QRViewController controller) { - this.controller = controller; + setState(() { + this.controller = controller; + }); controller.scannedDataStream.listen((scanData) { setState(() { result = scanData; diff --git a/pubspec.yaml b/pubspec.yaml index 88f840a..cd2a510 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: qr_code_scanner description: QR code scanner that can be embedded inside flutter. It uses zxing in Android and MTBBarcode scanner in iOS. -version: 0.2.1 +version: 0.3.0 homepage: https://juliuscanute.com repository: https://github.com/juliuscanute/qr_code_scanner