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(
... ... @@ -170,4 +169,4 @@ class _BarcodeListScannerWithControllerState
),
);
}
}
\ No newline at end of file
}
... ...
... ... @@ -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
... ... @@ -171,4 +170,4 @@ class _BarcodeScannerWithControllerState
),
);
}
}
\ No newline at end of file
}
... ...
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,
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!'))),
angle: 90 * pi / 180,
child: Image(
gaplessPlayback: true,
image: MemoryImage(barcode!.image!),
fit: BoxFit.contain,
),
)
: 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
... ... @@ -170,4 +180,4 @@ class _BarcodeScannerReturningImageState
),
);
}
}
\ No newline at end of file
}
... ...
... ... @@ -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
... ... @@ -66,4 +67,4 @@ class _BarcodeScannerWithoutControllerState
),
);
}
}
\ No newline at end of file
}
... ...
... ... @@ -23,7 +23,8 @@ class MyHome extends StatelessWidget {
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const BarcodeListScannerWithController(),
builder: (context) =>
const BarcodeListScannerWithController(),
),
);
},
... ... @@ -48,14 +49,14 @@ class MyHome extends StatelessWidget {
);
},
child:
const Text('MobileScanner with Controller (returning image)'),
const Text('MobileScanner with Controller (returning image)'),
),
ElevatedButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) =>
const BarcodeScannerWithoutController(),
const BarcodeScannerWithoutController(),
),
);
},
... ... @@ -66,4 +67,4 @@ class MyHome extends StatelessWidget {
),
);
}
}
\ No newline at end of file
}
... ...
... ... @@ -207,8 +207,8 @@ class ContactInfo {
/// Create a [ContactInfo] from native data.
ContactInfo.fromNative(Map data)
: addresses = List.unmodifiable(
(data['addresses'] as List).map((e) => Address.fromNative(e as Map)),
),
(data['addresses'] as List).map((e) => Address.fromNative(e as Map)),
),
emails = List.unmodifiable(
(data['emails'] as List).map((e) => Email.fromNative(e as Map)),
),
... ... @@ -768,4 +768,4 @@ enum EncryptionType {
///
/// Constant Value: 3
wep,
}
\ No newline at end of file
}
... ...
... ... @@ -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,9 +16,8 @@ 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)
onDetect;
final Function(BarcodeCapture capture, MobileScannerArguments? arguments)
onDetect;
/// Handles how the widget should fit the screen.
final BoxFit fit;
... ... @@ -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:
... ... @@ -128,4 +129,4 @@ class _MobileScannerState extends State<MobileScanner>
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
}
\ No newline at end of file
}
... ...
... ... @@ -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';
... ... @@ -65,13 +64,13 @@ class MobileScannerController {
/// Sets the barcode stream
final StreamController<BarcodeCapture> _barcodesController =
StreamController.broadcast();
StreamController.broadcast();
Stream<BarcodeCapture> get barcodes => _barcodesController.stream;
static const MethodChannel _methodChannel =
MethodChannel('dev.steenbakker.mobile_scanner/scanner/method');
MethodChannel('dev.steenbakker.mobile_scanner/scanner/method');
static const EventChannel _eventChannel =
EventChannel('dev.steenbakker.mobile_scanner/scanner/event');
EventChannel('dev.steenbakker.mobile_scanner/scanner/event');
Function(bool permissionGranted)? onPermissionSet;
... ... @@ -79,14 +78,15 @@ 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);
/// A notifier that provides the state of which camera is being used
late final ValueNotifier<CameraFacing> cameraFacingState =
ValueNotifier(facing);
ValueNotifier(facing);
bool isStarting = false;
bool? _hasTorch;
... ... @@ -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,13 +211,14 @@ 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');
}
torchState.value =
torchState.value == TorchState.off ? TorchState.on : TorchState.off;
torchState.value == TorchState.off ? TorchState.on : TorchState.off;
await _methodChannel.invokeMethod('torch', torchState.value.index);
}
... ... @@ -227,9 +229,9 @@ class MobileScannerController {
Future<void> switchCamera() async {
await _methodChannel.invokeMethod('stop');
final CameraFacing facingToUse =
cameraFacingState.value == CameraFacing.back
? CameraFacing.front
: CameraFacing.back;
cameraFacingState.value == CameraFacing.back
? CameraFacing.front
: CameraFacing.back;
await start(cameraFacingOverride: facingToUse);
}
... ... @@ -272,10 +274,12 @@ class MobileScannerController {
final parsed = (data as List)
.map((value) => Barcode.fromNative(value as Map))
.toList();
_barcodesController.add(BarcodeCapture(
barcodes: parsed,
image: event['image'] as Uint8List,
));
_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: [
Barcode(
rawValue: data as String?,
)
]));
_barcodesController.add(
BarcodeCapture(
barcodes: [
Barcode(
rawValue: data as String?,
)
],
),
);
break;
case 'error':
throw MobileScannerException(data as String);
... ... @@ -301,4 +309,4 @@ class MobileScannerController {
throw UnimplementedError(name as String?);
}
}
}
\ No newline at end of file
}
... ...
... ... @@ -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:
... ...