Selaa lähdekoodia

Merge branch master with feature/scannerOverlay

flutter-beta
Luis Thein 7 vuotta sitten
vanhempi
commit
5d4d8250ea
3 muutettua tiedostoa jossa 58 lisäystä ja 34 poistoa
  1. +40
    -20
      README.md
  2. +12
    -9
      example/lib/main.dart
  3. +6
    -5
      lib/qr_code_scanner.dart

+ 40
- 20
README.md Näytä tiedosto

@@ -60,31 +60,39 @@ class _QRViewExampleState extends State<QRViewExample> {
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: <Widget>[
QRView(
key: qrKey,
onQRViewCreated: _onQRViewCreated,
),
],
),
);
children: <Widget>[
Expanded(
flex: 5,
child: QRView(
key: qrKey,
onQRViewCreated: _onQRViewCreated,
),
),
Expanded(
flex: 1,
child: Center(
child: Text('Scan result: $qrText'),
),
)
],
),
);
}

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();
});
}
controller.scannedDataStream.listen((scanData) {
setState(() {
qrText = scanData;
});
});
}

@override
void dispose() {
controller?.dispose();
super.dispose();
}
}
```

@@ -104,9 +112,21 @@ controller.flipCamera();
## Flash (Off/On)
By default, flash is OFF.
```dart
controller.flipFlash();
controller.toggleFlash();
```

## Resume/Pause
Pause camera stream and scanner.
```dart
controller.pause();
```
Resume camera stream and scanner.
```dart
controller.resume();
```



# 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.
* In future, options will be provided for default states.


+ 12
- 9
example/lib/main.dart Näytä tiedosto

@@ -48,6 +48,7 @@ class _QRViewExampleState extends State<QRViewExample> {
child: FittedBox(
fit: BoxFit.contain,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text("This is the result of scan: $qrText"),
Row(
@@ -60,14 +61,15 @@ class _QRViewExampleState extends State<QRViewExample> {
onPressed: () {
if (controller != null) {
controller.toggleFlash();
if (_isFlashOn(flashState))
if (_isFlashOn(flashState)) {
setState(() {
flashState = flash_off;
});
else
} else {
setState(() {
flashState = flash_on;
});
}
}
},
child:
@@ -80,14 +82,15 @@ class _QRViewExampleState extends State<QRViewExample> {
onPressed: () {
if (controller != null) {
controller.flipCamera();
if (_isBackCamera(cameraState))
if (_isBackCamera(cameraState)) {
setState(() {
cameraState = front_camera;
});
else
} else {
setState(() {
cameraState = back_camera;
});
}
}
},
child:
@@ -97,11 +100,11 @@ class _QRViewExampleState extends State<QRViewExample> {
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
margin: EdgeInsets.only(bottom: 8.0),
margin: EdgeInsets.all(8.0),
child: RaisedButton(
onPressed: () {
controller?.pauseCamera();
@@ -110,10 +113,10 @@ class _QRViewExampleState extends State<QRViewExample> {
),
),
Container(
margin: EdgeInsets.only(bottom: 8.0),
margin: EdgeInsets.all(8.0),
child: RaisedButton(
onPressed: () {
controller.resumeCamera();
controller?.resumeCamera();
},
child: Text('resume', style: TextStyle(fontSize: 20)),
),
@@ -140,7 +143,7 @@ class _QRViewExampleState extends State<QRViewExample> {

void _onQRViewCreated(QRViewController controller) {
this.controller = controller;
controller.scannedData.listen((scanData) {
controller.scannedDataStream.listen((scanData) {
setState(() {
qrText = scanData;
});


+ 6
- 5
lib/qr_code_scanner.dart Näytä tiedosto

@@ -12,6 +12,7 @@ class QRView extends StatefulWidget {
@required this.onQRViewCreated,
this.overlay,
}) : assert(key != null),
assert(onQRViewCreated != null),
super(key: key);

final QRViewCreatedCallback onQRViewCreated;
@@ -95,14 +96,14 @@ class _CreationParams {
class QRViewController {
static const scanMethodCall = "onRecognizeQR";

StreamController<String> _scanUpdateController = StreamController<String>();
final MethodChannel _channel;

Stream<String> get scannedData => _scanUpdateController.stream;
StreamController<String> _scanUpdateController = StreamController<String>();

MethodChannel _channel;
Stream<String> get scannedDataStream => _scanUpdateController.stream;

QRViewController._(int id, GlobalKey qrKey) {
_channel = MethodChannel('net.touchcapture.qr.flutterqr/qrview_$id');
QRViewController._(int id, GlobalKey qrKey)
: _channel = MethodChannel('net.touchcapture.qr.flutterqr/qrview_$id') {
if (defaultTargetPlatform == TargetPlatform.iOS) {
final RenderBox renderBox = qrKey.currentContext.findRenderObject();
_channel.invokeMethod("setDimensions",


Ladataan…
Peruuta
Tallenna