瀏覽代碼

update README.md

flutter-beta
TheJuliuscanute 7 年之前
父節點
當前提交
93adab4def
共有 8 個文件被更改,包括 180 次插入20 次删除
  1. +1
    -1
      .packages
  2. 二進制
      .resources/android_back_camera_flash.gif
  3. 二進制
      .resources/android_front_camera_scan.gif
  4. 二進制
      .resources/ios_back_camera_flash.gif
  5. 二進制
      .resources/ios_front_camera_scan.gif
  6. 二進制
      .resources/sample_qr_code.png
  7. +117
    -7
      README.md
  8. +62
    -12
      example/lib/main.dart

+ 1
- 1
.packages 查看文件

@@ -1,4 +1,4 @@
# Generated by pub on 2019-06-18 09:09:30.310062.
# Generated by pub on 2019-06-18 10:12:43.975273.
collection:file:///Users/juliuscanute/.pub-cache/hosted/pub.dartlang.org/collection-1.14.11/lib/
flutter:file:///Users/juliuscanute/Library/CrossPlatform/flutter/packages/flutter/lib/
meta:file:///Users/juliuscanute/.pub-cache/hosted/pub.dartlang.org/meta-1.1.6/lib/


二進制
.resources/android_back_camera_flash.gif 查看文件

Before After
Width: 320  |  Height: 646  |  Size: 12 MiB

二進制
.resources/android_front_camera_scan.gif 查看文件

Before After
Width: 320  |  Height: 646  |  Size: 4.7 MiB

二進制
.resources/ios_back_camera_flash.gif 查看文件

Before After
Width: 320  |  Height: 566  |  Size: 6.6 MiB

二進制
.resources/ios_front_camera_scan.gif 查看文件

Before After
Width: 320  |  Height: 535  |  Size: 6.9 MiB

二進制
.resources/sample_qr_code.png 查看文件

Before After
Width: 300  |  Height: 300  |  Size: 2.7 KiB

+ 117
- 7
README.md 查看文件

@@ -1,11 +1,121 @@
# qr_code_scanner
This package wires the PlatformView corresponding to iOS and Android inside flutter.
# QR Code Scanner

# Credits
* Android: https://github.com/zxing/zxing
* iOS: https://github.com/mikebuss/MTBBarcodeScanner
* Special Thanks To: LeonDevLifeLog for his contributions towards improving this package.
A QR code scanner that works on both iOS and Android by natively embedding the platform view within Flutter. The integration with Flutter is seamless, much better than jumping into a native Activity or a ViewController to perform the scan.


## Screenshots
<table>
<tr>
<th colspan="2">
Android
</th>
</tr>

<tr>
<td>
<p align="center">
<figure>
<img src="/.resources/android_back_camera_flash.gif" width="30%" height="30%">
<figcaption>Back Camera Scan & Flash Test</figcaption>
</figure>
</p>
</td>
<td>
<p align="center">
<figure>
<img src="/.resources/android_front_camera_scan.gif" width="30%" height="30%">
<figcaption>Front Camera Scan</figcaption>
</figure>
</p>
</td>
</tr>

<tr>
<th colspan="2">
iOS
</th>
</tr>

<tr>
<td>
<p align="center">
<figure>
<img src="/.resources/ios_back_camera_flash.gif" width="30%" height="30%">
<figcaption>Back Camera Scan & Flash Test</figcaption>
</figure>
</p>
</td>
<td>
<p align="center">
<figure>
<img src="/.resources/ios_front_camera_scan.gif" width="30%" height="30%">
<figcaption>Front Camera Scan</figcaption>
</figure>
</p>
</td>
</tr>

</table>

## Get Scanned QR Code

When a QR code is recognized, the text identified will be set in 'qrText'.

```dart
class _QRViewExampleState extends State<QRViewExample> {
final GlobalKey qrKey = GlobalKey(debugLabel: 'QR');
var qrText = "";
QRViewController controller;

@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: <Widget>[
QRView(
key: qrKey,
onQRViewCreated: _onQRViewCreated,
),
],
),
);
}

void _onQRViewCreated(QRViewController controller) {
final channel = controller.channel;
controller.init(qrKey);
this.controller = controller;
channel.setMethodCallHandler((MethodCall call) async {
switch (call.method) {
case "onRecognizeQR":
dynamic arguments = call.arguments;
setState(() {
qrText = arguments.toString();
});
}
});
}
}
```
## Flip Camera (Back/Front)
The default camera is the back camera.
```dart
controller.flipCamera();
```

## Flash (Off/On)
By default, flash is OFF.
```dart
controller.flipFlash();
```

# TODO'S:
* iOS Native embedding is written to match what is supported in the framework as of the date of publication of this package. It needs to be improved as the framework support improves.
* Finally, I welcome PR's to make it better :), thanks
* In future, options will be provided for default states.
* Finally, I welcome PR's to make it better :), thanks

# Credits
* Android: https://github.com/zxing/zxing
* iOS: https://github.com/mikebuss/MTBBarcodeScanner
* Special Thanks To: LeonDevLifeLog for his contributions towards improving this package.

+ 62
- 12
example/lib/main.dart 查看文件

@@ -4,6 +4,11 @@ import 'package:qr_code_scanner/qr_code_scanner.dart';

void main() => runApp(MaterialApp(home: QRViewExample()));

const flash_on = "FLASH ON";
const flash_off = "FLASH OFF";
const front_camera = "FRONT CAMERA";
const back_camera = "BACK CAMERA";

class QRViewExample extends StatefulWidget {
const QRViewExample({
Key key,
@@ -16,7 +21,10 @@ class QRViewExample extends StatefulWidget {
class _QRViewExampleState extends State<QRViewExample> {
final GlobalKey qrKey = GlobalKey(debugLabel: 'QR');
var qrText = "";
var flashState = flash_on;
var cameraState = front_camera;
QRViewController controller;

@override
Widget build(BuildContext context) {
return Scaffold(
@@ -30,19 +38,53 @@ class _QRViewExampleState extends State<QRViewExample> {
flex: 4,
),
Expanded(
child: Column(children:
<Widget>[
child: Column(
children: <Widget>[
Text("This is the result of scan: $qrText"),
RaisedButton(
onPressed: (){
if(controller != null){
controller.flipFlash();
}
},
child: Text(
'Flip',
style: TextStyle(fontSize: 20)
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
margin: EdgeInsets.all(8.0),
child: RaisedButton(
onPressed: () {
if (controller != null) {
controller.flipFlash();
if (_isFlashOn(flashState))
setState(() {
flashState = flash_off;
});
else
setState(() {
flashState = flash_on;
});
}
},
child: Text(flashState, style: TextStyle(fontSize: 20)),
),
),
Container(
margin: EdgeInsets.all(8.0),
child: RaisedButton(
onPressed: () {
if (controller != null) {
controller.flipCamera();
if (_isBackCamera(cameraState))
setState(() {
cameraState = front_camera;
});
else
setState(() {
cameraState = back_camera;
});
}
},
child:
Text(cameraState, style: TextStyle(fontSize: 20)),
),
)
],
)
],
),
@@ -53,6 +95,14 @@ class _QRViewExampleState extends State<QRViewExample> {
);
}

_isFlashOn(String current) {
return flash_on == current;
}

_isBackCamera(String current) {
return back_camera == current;
}

void _onQRViewCreated(QRViewController controller) {
final channel = controller.channel;
controller.init(qrKey);


Loading…
取消
儲存