Pārlūkot izejas kodu

Release of v0.3.0

flutter-beta
Julian Steenbakker pirms 5 gadiem
vecāks
revīzija
9336171a2e
3 mainītis faili ar 61 papildinājumiem un 71 dzēšanām
  1. +16
    -1
      CHANGELOG.md
  2. +44
    -69
      example/README.md
  3. +1
    -1
      pubspec.yaml

+ 16
- 1
CHANGELOG.md Parādīt failu

@@ -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 ## 0.2.1
* Fixed critical bug where scanner wouldn't open when no scan overlay was configured. * Fixed critical bug where scanner wouldn't open when no scan overlay was configured.


@@ -29,7 +44,7 @@


## 0.0.12 ## 0.0.12
* Add optional parameter to use a camera overlay. * Add optional parameter to use a camera overlay.
* Simplfiy controller, expose scanDataStream.
* Simplify controller, expose scanDataStream.
* Fix for Android flash toggle. * Fix for Android flash toggle.
* Add ability to pause/resume the camera. * Add ability to pause/resume the camera.
* Thanks! to Luis Thein for all the above contributions. * Thanks! to Luis Thein for all the above contributions.


+ 44
- 69
example/README.md Parādīt failu

@@ -21,16 +21,14 @@ Demonstrates how to use the qr_code_scanner plugin.


## Example: ## Example:
```dart ```dart
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:qr_code_scanner/qr_code_scanner.dart'; import 'package:qr_code_scanner/qr_code_scanner.dart';


void main() => runApp(MaterialApp(home: QRViewExample())); 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 { class QRViewExample extends StatefulWidget {
const QRViewExample({ const QRViewExample({
Key key, Key key,
@@ -42,8 +40,6 @@ class QRViewExample extends StatefulWidget {


class _QRViewExampleState extends State<QRViewExample> { class _QRViewExampleState extends State<QRViewExample> {
Barcode result; Barcode result;
var flashState = flashOn;
var cameraState = frontCamera;
QRViewController controller; QRViewController controller;
final GlobalKey qrKey = GlobalKey(debugLabel: 'QR'); final GlobalKey qrKey = GlobalKey(debugLabel: 'QR');


@@ -84,44 +80,33 @@ class _QRViewExampleState extends State<QRViewExample> {
Container( Container(
margin: EdgeInsets.all(8), margin: EdgeInsets.all(8),
child: RaisedButton( 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( Container(
margin: EdgeInsets.all(8), margin: EdgeInsets.all(8),
child: RaisedButton( 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<QRViewExample> {
); );
} }


bool _isFlashOn(String current) {
return flashOn == current;
}

bool _isBackCamera(String current) {
return backCamera == current;
}

Widget _buildQrView(BuildContext context) { Widget _buildQrView(BuildContext context) {
// For this example we check how width or tall the device is and change the scanArea and overlay accordingly. // 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 || var scanArea = (MediaQuery.of(context).size.width < 400 ||
@@ -174,29 +151,27 @@ class _QRViewExampleState extends State<QRViewExample> {
: 300.0; : 300.0;
// To ensure the Scanner view is properly sizes after rotation // To ensure the Scanner view is properly sizes after rotation
// we need to listen for Flutter SizeChanged notification and update controller // we need to listen for Flutter SizeChanged notification and update controller
return NotificationListener<SizeChangedLayoutNotification>(
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) { void _onQRViewCreated(QRViewController controller) {
this.controller = controller;
setState(() {
this.controller = controller;
});
controller.scannedDataStream.listen((scanData) { controller.scannedDataStream.listen((scanData) {
setState(() { setState(() {
result = scanData; result = scanData;


+ 1
- 1
pubspec.yaml Parādīt failu

@@ -1,6 +1,6 @@
name: qr_code_scanner name: qr_code_scanner
description: QR code scanner that can be embedded inside flutter. It uses zxing in Android and MTBBarcode scanner in iOS. 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 homepage: https://juliuscanute.com
repository: https://github.com/juliuscanute/qr_code_scanner repository: https://github.com/juliuscanute/qr_code_scanner




Notiek ielāde…
Atcelt
Saglabāt