Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Remove unused barcode utility helpers #820

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## NEXT
Breaking changes:
* The internal `fromNative()` methods now accept a `Map<Object?, Object?>` instead of `Map<dynamic, dynamic>`.

Improvements:
* The `type` of an `Address` is now non-null.
* The `type` of an `Email` is now non-null.
Expand All @@ -10,7 +13,6 @@ Improvements:
* The `width` and `height` of `BarcodeCapture` are now non-null.
* The `BarcodeCapture` class now exposes a `size`.
* The list of `corners` of a `Barcode` is now non-null.
* The internal `fromNative()` methods now accept a `Map<Object?, Object?>` instead of `Map<dynamic, dynamic>`.

Bugs fixed:
* Fixed the default values for the `format` and `type` arguments of the Barcode constructor.
Expand Down
3 changes: 1 addition & 2 deletions lib/mobile_scanner_web_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'dart:ui' as ui;
import 'package:flutter/services.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
import 'package:mobile_scanner/mobile_scanner_web.dart';
import 'package:mobile_scanner/src/barcode_utility.dart';
import 'package:mobile_scanner/src/enums/barcode_format.dart';
import 'package:mobile_scanner/src/enums/camera_facing.dart';

Expand Down Expand Up @@ -110,7 +109,7 @@ class MobileScannerWebPlugin {
if (arguments.containsKey('formats')) {
formats = (arguments['formats'] as List)
.cast<int>()
.map((e) => toFormat(e))
.map(BarcodeFormat.fromRawValue)
.toList();
}

Expand Down
229 changes: 0 additions & 229 deletions lib/src/barcode_utility.dart

This file was deleted.

47 changes: 33 additions & 14 deletions lib/src/mobile_scanner_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,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_utility.dart';

/// The [MobileScannerController] holds all the logic of this plugin,
/// where as the [MobileScanner] class is the frontend of this plugin.
Expand Down Expand Up @@ -287,14 +286,26 @@ class MobileScannerController {
torchState.value = TorchState.on;
}

final Size size;

if (kIsWeb) {
size = Size(
startResult['videoWidth'] as double? ?? 0,
startResult['videoHeight'] as double? ?? 0,
);
} else {
final Map<Object?, Object?>? sizeInfo =
startResult['size'] as Map<Object?, Object?>?;

size = Size(
sizeInfo?['width'] as double? ?? 0,
sizeInfo?['height'] as double? ?? 0,
);
}

isStarting = false;
return startArguments.value = MobileScannerArguments(
size: kIsWeb
? Size(
startResult['videoWidth'] as double? ?? 0,
startResult['videoHeight'] as double? ?? 0,
)
: toSize(startResult['size'] as Map? ?? {}),
size: size,
hasTorch: hasTorch,
textureId: kIsWeb ? null : startResult['textureId'] as int?,
webId: kIsWeb ? startResult['ViewID'] as String? : null,
Expand Down Expand Up @@ -424,14 +435,18 @@ class MobileScannerController {
barcodes: [
Barcode(
rawValue: (data as Map)['payload'] as String?,
format: toFormat(data['symbology'] as int),
format: BarcodeFormat.fromRawValue(
data['symbology'] as int? ?? -1,
),
),
],
),
);
break;
case 'barcodeWeb':
final barcode = data as Map?;
final corners = barcode?['corners'] as List<Object?>? ?? <Object?>[];

_barcodesController.add(
BarcodeCapture(
raw: data,
Expand All @@ -440,12 +455,16 @@ class MobileScannerController {
Barcode(
rawValue: barcode['rawValue'] as String?,
rawBytes: barcode['rawBytes'] as Uint8List?,
format: toFormat(barcode['format'] as int),
corners: toCorners(
(barcode['corners'] as List<Object?>? ?? [])
.cast<Map<Object?, Object?>>(),
) ??
const <Offset>[],
format: BarcodeFormat.fromRawValue(
barcode['format'] as int? ?? -1,
),
corners: List.unmodifiable(
corners.cast<Map<Object?, Object?>>().map(
(Map<Object?, Object?> e) {
return Offset(e['x']! as double, e['y']! as double);
},
),
),
),
],
),
Expand Down