Julian Steenbakker

Merge branch 'feature/return-image-dart' into imp/return-image-ios

# Conflicts:
#	example/lib/barcode_scanner_controller.dart
... ... @@ -13,7 +13,6 @@ class BarcodeListScannerWithController extends StatefulWidget {
class _BarcodeListScannerWithControllerState
extends State<BarcodeListScannerWithController>
with SingleTickerProviderStateMixin {
BarcodeCapture? barcodeCapture;
MobileScannerController controller = MobileScannerController(
... ...
... ... @@ -13,12 +13,10 @@ class BarcodeScannerWithController extends StatefulWidget {
class _BarcodeScannerWithControllerState
extends State<BarcodeScannerWithController>
with SingleTickerProviderStateMixin {
BarcodeCapture? barcode;
MobileScannerController controller = MobileScannerController(
torchEnabled: true,
detectionSpeed: DetectionSpeed.normal
torchEnabled: true, detectionSpeed: DetectionSpeed.unrestricted,
// formats: [BarcodeFormat.qrCode]
// facing: CameraFacing.front,
);
... ... @@ -101,7 +99,8 @@ class _BarcodeScannerWithControllerState
height: 50,
child: FittedBox(
child: Text(
barcode?.barcodes.first.rawValue ?? 'Scan something!',
barcode?.barcodes.first.rawValue ??
'Scan something!',
overflow: TextOverflow.fade,
style: Theme.of(context)
.textTheme
... ...
import 'dart:math';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:mobile_scanner/mobile_scanner.dart';
... ... @@ -27,7 +26,6 @@ class _BarcodeScannerReturningImageState
bool isStarted = true;
@override
Widget build(BuildContext context) {
return Scaffold(
... ... @@ -42,14 +40,21 @@ class _BarcodeScannerReturningImageState
height: 0.33 * MediaQuery.of(context).size.height,
child: barcode?.image != null
? Transform.rotate(
angle: 90 * pi/180,
angle: 90 * pi / 180,
child: Image(
gaplessPlayback: true,
image: MemoryImage(barcode!.image!),
fit: BoxFit.contain,
),
)
: Container(color: Colors.white, child: const Center(child: Text('Your scanned barcode will appear here!'))),
: const ColoredBox(
color: Colors.white,
child: Center(
child: Text(
'Your scanned barcode will appear here!',
),
),
),
),
Container(
height: 0.66 * MediaQuery.of(context).size.height,
... ... @@ -80,8 +85,10 @@ class _BarcodeScannerReturningImageState
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
color: arguments != null && !arguments!.hasTorch ? Colors.red : Colors.white,
ColoredBox(
color: arguments != null && !arguments!.hasTorch
? Colors.red
: Colors.white,
child: IconButton(
// color: ,
icon: ValueListenableBuilder(
... ... @@ -118,7 +125,9 @@ class _BarcodeScannerReturningImageState
: const Icon(Icons.play_arrow),
iconSize: 32.0,
onPressed: () => setState(() {
isStarted ? controller.stop() : controller.start();
isStarted
? controller.stop()
: controller.start();
isStarted = !isStarted;
}),
),
... ... @@ -128,7 +137,8 @@ class _BarcodeScannerReturningImageState
height: 50,
child: FittedBox(
child: Text(
barcode?.barcodes.first.rawValue ?? 'Scan something!',
barcode?.barcodes.first.rawValue ??
'Scan something!',
overflow: TextOverflow.fade,
style: Theme.of(context)
.textTheme
... ...
... ... @@ -46,7 +46,8 @@ class _BarcodeScannerWithoutControllerState
height: 50,
child: FittedBox(
child: Text(
capture?.barcodes.first.rawValue ?? 'Scan something!',
capture?.barcodes.first.rawValue ??
'Scan something!',
overflow: TextOverflow.fade,
style: Theme.of(context)
.textTheme
... ...
... ... @@ -23,7 +23,8 @@ class MyHome extends StatelessWidget {
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const BarcodeListScannerWithController(),
builder: (context) =>
const BarcodeListScannerWithController(),
),
);
},
... ...
... ... @@ -10,5 +10,4 @@ class BarcodeCapture {
required this.barcodes,
this.image,
});
}
... ...
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:mobile_scanner/src/barcode_capture.dart';
import 'package:mobile_scanner/src/mobile_scanner_arguments.dart';
import 'package:mobile_scanner/src/mobile_scanner_controller.dart';
import 'package:mobile_scanner/src/barcode_capture.dart';
/// A widget showing a live camera preview.
class MobileScanner extends StatefulWidget {
... ... @@ -16,8 +16,7 @@ class MobileScanner extends StatefulWidget {
///
/// [barcode] The barcode object with all information about the scanned code.
/// [startArguments] Information about the state of the MobileScanner widget
final Function(
BarcodeCapture capture, MobileScannerArguments? arguments)
final Function(BarcodeCapture capture, MobileScannerArguments? arguments)
onDetect;
/// Handles how the widget should fit the screen.
... ... @@ -59,7 +58,9 @@ class _MobileScannerState extends State<MobileScanner>
void didChangeAppLifecycleState(AppLifecycleState state) {
switch (state) {
case AppLifecycleState.resumed:
if (!controller.isStarting && widget.autoResume && _lastState != AppLifecycleState.inactive) controller.start();
if (!controller.isStarting &&
widget.autoResume &&
_lastState != AppLifecycleState.inactive) controller.start();
break;
case AppLifecycleState.paused:
case AppLifecycleState.detached:
... ...
... ... @@ -5,7 +5,6 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:mobile_scanner/mobile_scanner.dart';
import 'package:mobile_scanner/src/barcode_capture.dart';
import 'package:mobile_scanner/src/barcode_utility.dart';
import 'package:mobile_scanner/src/mobile_scanner_exception.dart';
... ... @@ -79,7 +78,8 @@ class MobileScannerController {
late StreamSubscription events;
/// A notifier that provides several arguments about the MobileScanner
final ValueNotifier<MobileScannerArguments?> startArguments = ValueNotifier(null);
final ValueNotifier<MobileScannerArguments?> startArguments =
ValueNotifier(null);
/// A notifier that provides the state of the Torch (Flash)
final ValueNotifier<TorchState> torchState = ValueNotifier(TorchState.off);
... ... @@ -167,7 +167,8 @@ class MobileScannerController {
if (startResult == null) {
isStarting = false;
throw MobileScannerException(
'Failed to start mobileScanner, no response from platform side');
'Failed to start mobileScanner, no response from platform side',
);
}
_hasTorch = startResult['torchable'] as bool? ?? false;
... ... @@ -210,7 +211,8 @@ class MobileScannerController {
Future<void> toggleTorch() async {
if (_hasTorch == null) {
throw MobileScannerException(
'Cannot toggle torch if start() has never been called');
'Cannot toggle torch if start() has never been called',
);
} else if (!_hasTorch!) {
throw MobileScannerException('Device has no torch');
}
... ... @@ -272,10 +274,12 @@ class MobileScannerController {
final parsed = (data as List)
.map((value) => Barcode.fromNative(value as Map))
.toList();
_barcodesController.add(BarcodeCapture(
_barcodesController.add(
BarcodeCapture(
barcodes: parsed,
image: event['image'] as Uint8List,
));
),
);
break;
case 'barcodeMac':
_barcodesController.add(
... ... @@ -289,11 +293,15 @@ class MobileScannerController {
);
break;
case 'barcodeWeb':
_barcodesController.add(BarcodeCapture(barcodes: [
_barcodesController.add(
BarcodeCapture(
barcodes: [
Barcode(
rawValue: data as String?,
)
]));
],
),
);
break;
case 'error':
throw MobileScannerException(data as String);
... ...
... ... @@ -12,13 +12,12 @@ dependencies:
sdk: flutter
flutter_web_plugins:
sdk: flutter
json_serializable: ^6.3.1
js: ^0.6.3
dev_dependencies:
build_runner: ^2.2.0
flutter_test:
sdk: flutter
json_annotation: ^4.6.0
lint: ^1.10.0
flutter:
... ...