Julian Steenbakker

style: flutter format

... ... @@ -18,8 +18,10 @@ class _AnalyzeViewState extends State<AnalyzeView>
with SingleTickerProviderStateMixin {
String? barcode;
MobileScannerController controller = MobileScannerController(torchEnabled: true,
facing: CameraFacing.front,);
MobileScannerController controller = MobileScannerController(
torchEnabled: true,
facing: CameraFacing.front,
);
@override
Widget build(BuildContext context) {
... ... @@ -30,7 +32,7 @@ class _AnalyzeViewState extends State<AnalyzeView>
return Stack(
children: [
MobileScanner(
controller: controller,
controller: controller,
fit: BoxFit.contain,
// controller: MobileScannerController(
// torchEnabled: true,
... ... @@ -55,20 +57,22 @@ class _AnalyzeViewState extends State<AnalyzeView>
children: [
IconButton(
color: Colors.white,
icon: ValueListenableBuilder(
valueListenable: controller.torchState,
builder: (context, state, child) {
switch (state as TorchState) {
case TorchState.off:
return const Icon(Icons.flash_off, color: Colors.grey);
case TorchState.on:
return const Icon(Icons.flash_on, color: Colors.yellow);
}
},
),
iconSize: 32.0,
onPressed: () => controller.toggleTorch(),
icon: ValueListenableBuilder(
valueListenable: controller.torchState,
builder: (context, state, child) {
switch (state as TorchState) {
case TorchState.off:
return const Icon(Icons.flash_off,
color: Colors.grey);
case TorchState.on:
return const Icon(Icons.flash_on,
color: Colors.yellow);
}
},
),
iconSize: 32.0,
onPressed: () => controller.toggleTorch(),
),
Center(
child: SizedBox(
width: MediaQuery.of(context).size.width - 120,
... ...
... ... @@ -30,40 +30,41 @@ class _AnalyzeViewState extends State<AnalyzeView>
return Stack(
children: [
MobileScanner(
// fitScreen: false,
// fitScreen: false,
// controller: cameraController,
onDetect: (barcode, args) {
if (this.barcode != barcode.rawValue) {
this.barcode = barcode.rawValue;
if (barcode.corners != null) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('${barcode.rawValue}'),
duration: const Duration(milliseconds: 200),
animation: null,
));
setState(() {
final List<Offset> points = [];
double factorWidth = args.size.width / 520;
// double factorHeight = wanted / args.size.height;
final size = MediaQuery.of(context).devicePixelRatio;
debugPrint('Size: ${barcode.corners}');
for (var point in barcode.corners!) {
final adjustedWith = point.dx ;
final adjustedHeight= point.dy ;
points.add(Offset(adjustedWith / size, adjustedHeight / size));
// points.add(Offset((point.dx ) / size,
// (point.dy) / size));
// final differenceWidth = (args.wantedSize!.width - args.size.width) / 2;
// final differenceHeight = (args.wantedSize!.height - args.size.height) / 2;
// points.add(Offset((point.dx + differenceWidth) / size,
// (point.dy + differenceHeight) / size));
}
this.points = points;
});
if (this.barcode != barcode.rawValue) {
this.barcode = barcode.rawValue;
if (barcode.corners != null) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('${barcode.rawValue}'),
duration: const Duration(milliseconds: 200),
animation: null,
));
setState(() {
final List<Offset> points = [];
double factorWidth = args.size.width / 520;
// double factorHeight = wanted / args.size.height;
final size = MediaQuery.of(context).devicePixelRatio;
debugPrint('Size: ${barcode.corners}');
for (var point in barcode.corners!) {
final adjustedWith = point.dx;
final adjustedHeight = point.dy;
points.add(
Offset(adjustedWith / size, adjustedHeight / size));
// points.add(Offset((point.dx ) / size,
// (point.dy) / size));
// final differenceWidth = (args.wantedSize!.width - args.size.width) / 2;
// final differenceHeight = (args.wantedSize!.height - args.size.height) / 2;
// points.add(Offset((point.dx + differenceWidth) / size,
// (point.dy + differenceHeight) / size));
}
}
// Default 640 x480
}),
this.points = points;
});
}
}
// Default 640 x480
}),
CustomPaint(
painter: OpenPainter(points),
),
... ...
... ... @@ -2,4 +2,4 @@ library mobile_scanner;
export 'src/mobile_scanner.dart';
export 'src/mobile_scanner_controller.dart';
export 'src/objects/barcode.dart';
\ No newline at end of file
export 'src/objects/barcode.dart';
... ...
... ... @@ -3,10 +3,7 @@ import 'package:mobile_scanner/mobile_scanner.dart';
import 'mobile_scanner_arguments.dart';
enum Ratio {
ratio_4_3,
ratio_16_9
}
enum Ratio { ratio_4_3, ratio_16_9 }
/// A widget showing a live camera preview.
class MobileScanner extends StatefulWidget {
... ... @@ -18,7 +15,8 @@ class MobileScanner extends StatefulWidget {
/// Create a [MobileScanner] with a [controller], the [controller] must has been initialized.
const MobileScanner(
{Key? key, this.onDetect, this.controller, this.fit = BoxFit.cover})
: assert((controller != null )), super(key: key);
: assert((controller != null)),
super(key: key);
@override
State<MobileScanner> createState() => _MobileScannerState();
... ... @@ -91,4 +89,4 @@ class _MobileScannerState extends State<MobileScanner>
controller.dispose();
super.dispose();
}
}
\ No newline at end of file
}
... ...
... ... @@ -11,5 +11,6 @@ class MobileScannerArguments {
final bool hasTorch;
/// Create a [MobileScannerArguments].
MobileScannerArguments({required this.textureId,required this.size, required this.hasTorch});
MobileScannerArguments(
{required this.textureId, required this.size, required this.hasTorch});
}
... ...
... ... @@ -38,7 +38,6 @@ class MobileScannerController {
int? _controllerHashcode;
StreamSubscription? events;
final ValueNotifier<MobileScannerArguments?> args = ValueNotifier(null);
final ValueNotifier<TorchState> torchState = ValueNotifier(TorchState.off);
late final ValueNotifier<CameraFacing> cameraFacingState;
... ... @@ -107,7 +106,8 @@ class MobileScannerController {
setAnalyzeMode(AnalyzeMode.barcode.index);
// Check authorization status
MobileScannerState state = MobileScannerState.values[await methodChannel.invokeMethod('state')];
MobileScannerState state =
MobileScannerState.values[await methodChannel.invokeMethod('state')];
switch (state) {
case MobileScannerState.undetermined:
final bool result = await methodChannel.invokeMethod('request');
... ... @@ -129,13 +129,17 @@ class MobileScannerController {
if (torchEnabled != null) arguments['torch'] = torchEnabled;
// Start the camera with arguments
final Map<String, dynamic>? startResult = await methodChannel.invokeMapMethod<String, dynamic>(
'start', arguments);
final Map<String, dynamic>? startResult = await methodChannel
.invokeMapMethod<String, dynamic>('start', arguments);
if (startResult == null) throw PlatformException(code: 'INITIALIZATION ERROR');
if (startResult == null)
throw PlatformException(code: 'INITIALIZATION ERROR');
hasTorch = startResult['torchable'];
args.value = MobileScannerArguments(textureId: startResult['textureId'], size: toSize(startResult['size']), hasTorch: hasTorch);
args.value = MobileScannerArguments(
textureId: startResult['textureId'],
size: toSize(startResult['size']),
hasTorch: hasTorch);
}
Future<void> stop() async => await methodChannel.invokeMethod('stop');
... ... @@ -157,7 +161,8 @@ class MobileScannerController {
Future<void> switchCamera() async {
ensure('switchCamera');
await stop();
facing = facing == CameraFacing.back ? CameraFacing.front : CameraFacing.back;
facing =
facing == CameraFacing.back ? CameraFacing.front : CameraFacing.back;
start();
}
... ...
... ... @@ -16,5 +16,4 @@ void main() {
tearDown(() {
channel.setMockMethodCallHandler(null);
});
}
... ...