Browse Source

added flash support

pull/3/head
Khoren Markosyan 3 years ago
parent
commit
d09c9ebc39
  1. 2
      example/pubspec.lock
  2. 68
      lib/reader_widget.dart
  3. 4
      zxscanner/pubspec.lock
  4. 2
      zxscanner/pubspec.yaml

2
example/pubspec.lock

@ -141,7 +141,7 @@ packages:
path: ".." path: ".."
relative: true relative: true
source: path source: path
version: "0.1.3" version: "0.2.0"
font_awesome_flutter: font_awesome_flutter:
dependency: "direct main" dependency: "direct main"
description: description:

68
lib/reader_widget.dart

@ -18,7 +18,8 @@ class ReaderWidget extends StatefulWidget {
this.codeFormat = Format.Any, this.codeFormat = Format.Any,
this.beep = true, this.beep = true,
this.showCroppingRect = true, this.showCroppingRect = true,
this.scanDelay = const Duration(milliseconds: 500), // 500ms delay this.showFlashlight = true,
this.scanDelay = const Duration(milliseconds: 1000), // 1000ms delay
this.cropPercent = 0.5, // 50% of the screen this.cropPercent = 0.5, // 50% of the screen
this.resolution = ResolutionPreset.high, this.resolution = ResolutionPreset.high,
}) : super(key: key); }) : super(key: key);
@ -28,6 +29,7 @@ class ReaderWidget extends StatefulWidget {
final int codeFormat; final int codeFormat;
final bool beep; final bool beep;
final bool showCroppingRect; final bool showCroppingRect;
final bool showFlashlight;
final Duration scanDelay; final Duration scanDelay;
final double cropPercent; final double cropPercent;
final ResolutionPreset resolution; final ResolutionPreset resolution;
@ -112,6 +114,7 @@ class _ReaderWidgetState extends State<ReaderWidget>
try { try {
await controller?.initialize(); await controller?.initialize();
await controller?.setFlashMode(FlashMode.off);
controller?.startImageStream(processCameraImage); controller?.startImageStream(processCameraImage);
} on CameraException catch (e) { } on CameraException catch (e) {
debugPrint('${e.code}: ${e.description}'); debugPrint('${e.code}: ${e.description}');
@ -202,22 +205,57 @@ class _ReaderWidgetState extends State<ReaderWidget>
), ),
), ),
), ),
widget.showCroppingRect if (widget.showCroppingRect)
? Container( Container(
decoration: ShapeDecoration( decoration: ShapeDecoration(
shape: ScannerOverlay( shape: ScannerOverlay(
borderColor: Theme.of(context).primaryColor, borderColor: Theme.of(context).primaryColor,
overlayColor: const Color.fromRGBO(0, 0, 0, 0.5), overlayColor: const Color.fromRGBO(0, 0, 0, 0.5),
borderRadius: 1, borderRadius: 1,
borderLength: 16, borderLength: 16,
borderWidth: 8, borderWidth: 8,
cutOutSize: cropSize, cutOutSize: cropSize,
), ),
), ),
) ),
: Container() if (widget.showFlashlight)
Positioned(
top: 20,
left: 20,
child: FloatingActionButton(
onPressed: () {
FlashMode mode = cameraController.value.flashMode;
switch (mode) {
case FlashMode.torch:
mode = FlashMode.off;
break;
case FlashMode.off:
mode = FlashMode.torch;
break;
default:
}
cameraController.setFlashMode(mode);
setState(() {});
},
mini: true,
backgroundColor: Colors.black26,
child: Icon(_flashIcon(cameraController)),
),
)
], ],
); );
} }
} }
IconData _flashIcon(CameraController cameraController) {
final FlashMode mode = cameraController.value.flashMode;
switch (mode) {
case FlashMode.torch:
return Icons.flash_on;
case FlashMode.off:
return Icons.flash_off;
default:
return Icons.flash_off;
}
}
} }

4
zxscanner/pubspec.lock

@ -300,7 +300,7 @@ packages:
path: ".." path: ".."
relative: true relative: true
source: path source: path
version: "0.1.3" version: "0.2.0"
font_awesome_flutter: font_awesome_flutter:
dependency: "direct main" dependency: "direct main"
description: description:
@ -629,7 +629,7 @@ packages:
name: share_plus name: share_plus
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "4.0.6" version: "4.0.7"
share_plus_linux: share_plus_linux:
dependency: transitive dependency: transitive
description: description:

2
zxscanner/pubspec.yaml

@ -27,7 +27,7 @@ dependencies:
intl: ^0.17.0 intl: ^0.17.0
mobx: ^2.0.7 mobx: ^2.0.7
path_provider: ^2.0.10 path_provider: ^2.0.10
share_plus: ^4.0.6 share_plus: ^4.0.7
shared_preferences: ^2.0.15 shared_preferences: ^2.0.15
url_launcher: ^6.1.2 url_launcher: ^6.1.2

Loading…
Cancel
Save