Committed by
GitHub
Merge pull request #820 from navaronbracke/remove_barcode_utility
feat: Remove unused barcode utility helpers
Showing
4 changed files
with
37 additions
and
246 deletions
| 1 | ## NEXT | 1 | ## NEXT |
| 2 | +Breaking changes: | ||
| 3 | +* The internal `fromNative()` methods now accept a `Map<Object?, Object?>` instead of `Map<dynamic, dynamic>`. | ||
| 4 | + | ||
| 2 | Improvements: | 5 | Improvements: |
| 3 | * The `type` of an `Address` is now non-null. | 6 | * The `type` of an `Address` is now non-null. |
| 4 | * The `type` of an `Email` is now non-null. | 7 | * The `type` of an `Email` is now non-null. |
| @@ -10,7 +13,6 @@ Improvements: | @@ -10,7 +13,6 @@ Improvements: | ||
| 10 | * The `width` and `height` of `BarcodeCapture` are now non-null. | 13 | * The `width` and `height` of `BarcodeCapture` are now non-null. |
| 11 | * The `BarcodeCapture` class now exposes a `size`. | 14 | * The `BarcodeCapture` class now exposes a `size`. |
| 12 | * The list of `corners` of a `Barcode` is now non-null. | 15 | * The list of `corners` of a `Barcode` is now non-null. |
| 13 | -* The internal `fromNative()` methods now accept a `Map<Object?, Object?>` instead of `Map<dynamic, dynamic>`. | ||
| 14 | 16 | ||
| 15 | Bugs fixed: | 17 | Bugs fixed: |
| 16 | * Fixed the default values for the `format` and `type` arguments of the Barcode constructor. | 18 | * Fixed the default values for the `format` and `type` arguments of the Barcode constructor. |
| @@ -5,7 +5,6 @@ import 'dart:ui' as ui; | @@ -5,7 +5,6 @@ import 'dart:ui' as ui; | ||
| 5 | import 'package:flutter/services.dart'; | 5 | import 'package:flutter/services.dart'; |
| 6 | import 'package:flutter_web_plugins/flutter_web_plugins.dart'; | 6 | import 'package:flutter_web_plugins/flutter_web_plugins.dart'; |
| 7 | import 'package:mobile_scanner/mobile_scanner_web.dart'; | 7 | import 'package:mobile_scanner/mobile_scanner_web.dart'; |
| 8 | -import 'package:mobile_scanner/src/barcode_utility.dart'; | ||
| 9 | import 'package:mobile_scanner/src/enums/barcode_format.dart'; | 8 | import 'package:mobile_scanner/src/enums/barcode_format.dart'; |
| 10 | import 'package:mobile_scanner/src/enums/camera_facing.dart'; | 9 | import 'package:mobile_scanner/src/enums/camera_facing.dart'; |
| 11 | 10 | ||
| @@ -110,7 +109,7 @@ class MobileScannerWebPlugin { | @@ -110,7 +109,7 @@ class MobileScannerWebPlugin { | ||
| 110 | if (arguments.containsKey('formats')) { | 109 | if (arguments.containsKey('formats')) { |
| 111 | formats = (arguments['formats'] as List) | 110 | formats = (arguments['formats'] as List) |
| 112 | .cast<int>() | 111 | .cast<int>() |
| 113 | - .map((e) => toFormat(e)) | 112 | + .map(BarcodeFormat.fromRawValue) |
| 114 | .toList(); | 113 | .toList(); |
| 115 | } | 114 | } |
| 116 | 115 |
lib/src/barcode_utility.dart
deleted
100644 → 0
| 1 | -import 'dart:math' as math; | ||
| 2 | - | ||
| 3 | -import 'package:flutter/material.dart'; | ||
| 4 | -import 'package:mobile_scanner/mobile_scanner.dart'; | ||
| 5 | - | ||
| 6 | -Size toSize(Map data) { | ||
| 7 | - final width = data['width'] as double; | ||
| 8 | - final height = data['height'] as double; | ||
| 9 | - return Size(width, height); | ||
| 10 | -} | ||
| 11 | - | ||
| 12 | -List<Offset>? toCorners(List<Map<Object?, Object?>>? data) { | ||
| 13 | - if (data == null) { | ||
| 14 | - return null; | ||
| 15 | - } | ||
| 16 | - | ||
| 17 | - return List.unmodifiable( | ||
| 18 | - data.map((Map<Object?, Object?> e) { | ||
| 19 | - return Offset(e['x']! as double, e['y']! as double); | ||
| 20 | - }), | ||
| 21 | - ); | ||
| 22 | -} | ||
| 23 | - | ||
| 24 | -BarcodeFormat toFormat(int value) { | ||
| 25 | - switch (value) { | ||
| 26 | - case 0: | ||
| 27 | - return BarcodeFormat.all; | ||
| 28 | - case 1: | ||
| 29 | - return BarcodeFormat.code128; | ||
| 30 | - case 2: | ||
| 31 | - return BarcodeFormat.code39; | ||
| 32 | - case 4: | ||
| 33 | - return BarcodeFormat.code93; | ||
| 34 | - case 8: | ||
| 35 | - return BarcodeFormat.codebar; | ||
| 36 | - case 16: | ||
| 37 | - return BarcodeFormat.dataMatrix; | ||
| 38 | - case 32: | ||
| 39 | - return BarcodeFormat.ean13; | ||
| 40 | - case 64: | ||
| 41 | - return BarcodeFormat.ean8; | ||
| 42 | - case 128: | ||
| 43 | - return BarcodeFormat.itf; | ||
| 44 | - case 256: | ||
| 45 | - return BarcodeFormat.qrCode; | ||
| 46 | - case 512: | ||
| 47 | - return BarcodeFormat.upcA; | ||
| 48 | - case 1024: | ||
| 49 | - return BarcodeFormat.upcE; | ||
| 50 | - case 2048: | ||
| 51 | - return BarcodeFormat.pdf417; | ||
| 52 | - case 4096: | ||
| 53 | - return BarcodeFormat.aztec; | ||
| 54 | - default: | ||
| 55 | - return BarcodeFormat.unknown; | ||
| 56 | - } | ||
| 57 | -} | ||
| 58 | - | ||
| 59 | -CalendarEvent? toCalendarEvent(Map? data) { | ||
| 60 | - if (data != null) { | ||
| 61 | - return CalendarEvent.fromNative(data); | ||
| 62 | - } else { | ||
| 63 | - return null; | ||
| 64 | - } | ||
| 65 | -} | ||
| 66 | - | ||
| 67 | -DateTime? toDateTime(Map<String, dynamic>? data) { | ||
| 68 | - if (data != null) { | ||
| 69 | - final year = data['year'] as int; | ||
| 70 | - final month = data['month'] as int; | ||
| 71 | - final day = data['day'] as int; | ||
| 72 | - final hour = data['hours'] as int; | ||
| 73 | - final minute = data['minutes'] as int; | ||
| 74 | - final second = data['seconds'] as int; | ||
| 75 | - return data['isUtc'] as bool | ||
| 76 | - ? DateTime.utc(year, month, day, hour, minute, second) | ||
| 77 | - : DateTime(year, month, day, hour, minute, second); | ||
| 78 | - } else { | ||
| 79 | - return null; | ||
| 80 | - } | ||
| 81 | -} | ||
| 82 | - | ||
| 83 | -ContactInfo? toContactInfo(Map? data) { | ||
| 84 | - if (data != null) { | ||
| 85 | - return ContactInfo.fromNative(data); | ||
| 86 | - } else { | ||
| 87 | - return null; | ||
| 88 | - } | ||
| 89 | -} | ||
| 90 | - | ||
| 91 | -PersonName? toName(Map? data) { | ||
| 92 | - if (data != null) { | ||
| 93 | - return PersonName.fromNative(data); | ||
| 94 | - } else { | ||
| 95 | - return null; | ||
| 96 | - } | ||
| 97 | -} | ||
| 98 | - | ||
| 99 | -DriverLicense? toDriverLicense(Map? data) { | ||
| 100 | - if (data != null) { | ||
| 101 | - return DriverLicense.fromNative(data); | ||
| 102 | - } else { | ||
| 103 | - return null; | ||
| 104 | - } | ||
| 105 | -} | ||
| 106 | - | ||
| 107 | -Email? toEmail(Map? data) { | ||
| 108 | - if (data != null) { | ||
| 109 | - return Email.fromNative(data); | ||
| 110 | - } else { | ||
| 111 | - return null; | ||
| 112 | - } | ||
| 113 | -} | ||
| 114 | - | ||
| 115 | -GeoPoint? toGeoPoint(Map? data) { | ||
| 116 | - if (data != null) { | ||
| 117 | - return GeoPoint.fromNative(data); | ||
| 118 | - } else { | ||
| 119 | - return null; | ||
| 120 | - } | ||
| 121 | -} | ||
| 122 | - | ||
| 123 | -Phone? toPhone(Map? data) { | ||
| 124 | - if (data != null) { | ||
| 125 | - return Phone.fromNative(data); | ||
| 126 | - } else { | ||
| 127 | - return null; | ||
| 128 | - } | ||
| 129 | -} | ||
| 130 | - | ||
| 131 | -SMS? toSMS(Map? data) { | ||
| 132 | - if (data != null) { | ||
| 133 | - return SMS.fromNative(data); | ||
| 134 | - } else { | ||
| 135 | - return null; | ||
| 136 | - } | ||
| 137 | -} | ||
| 138 | - | ||
| 139 | -UrlBookmark? toUrl(Map? data) { | ||
| 140 | - if (data != null) { | ||
| 141 | - return UrlBookmark.fromNative(data); | ||
| 142 | - } else { | ||
| 143 | - return null; | ||
| 144 | - } | ||
| 145 | -} | ||
| 146 | - | ||
| 147 | -WiFi? toWiFi(Map? data) { | ||
| 148 | - if (data != null) { | ||
| 149 | - return WiFi.fromNative(data); | ||
| 150 | - } else { | ||
| 151 | - return null; | ||
| 152 | - } | ||
| 153 | -} | ||
| 154 | - | ||
| 155 | -Size applyBoxFit(BoxFit fit, Size input, Size output) { | ||
| 156 | - if (input.height <= 0.0 || | ||
| 157 | - input.width <= 0.0 || | ||
| 158 | - output.height <= 0.0 || | ||
| 159 | - output.width <= 0.0) { | ||
| 160 | - return Size.zero; | ||
| 161 | - } | ||
| 162 | - | ||
| 163 | - Size destination; | ||
| 164 | - | ||
| 165 | - final inputAspectRatio = input.width / input.height; | ||
| 166 | - final outputAspectRatio = output.width / output.height; | ||
| 167 | - | ||
| 168 | - switch (fit) { | ||
| 169 | - case BoxFit.fill: | ||
| 170 | - destination = output; | ||
| 171 | - break; | ||
| 172 | - case BoxFit.contain: | ||
| 173 | - if (outputAspectRatio > inputAspectRatio) { | ||
| 174 | - destination = Size( | ||
| 175 | - input.width * output.height / input.height, | ||
| 176 | - output.height, | ||
| 177 | - ); | ||
| 178 | - } else { | ||
| 179 | - destination = Size( | ||
| 180 | - output.width, | ||
| 181 | - input.height * output.width / input.width, | ||
| 182 | - ); | ||
| 183 | - } | ||
| 184 | - break; | ||
| 185 | - | ||
| 186 | - case BoxFit.cover: | ||
| 187 | - if (outputAspectRatio > inputAspectRatio) { | ||
| 188 | - destination = Size( | ||
| 189 | - output.width, | ||
| 190 | - input.height * (output.width / input.width), | ||
| 191 | - ); | ||
| 192 | - } else { | ||
| 193 | - destination = Size( | ||
| 194 | - input.width * (output.height / input.height), | ||
| 195 | - output.height, | ||
| 196 | - ); | ||
| 197 | - } | ||
| 198 | - break; | ||
| 199 | - case BoxFit.fitWidth: | ||
| 200 | - destination = Size( | ||
| 201 | - output.width, | ||
| 202 | - input.height * (output.width / input.width), | ||
| 203 | - ); | ||
| 204 | - break; | ||
| 205 | - case BoxFit.fitHeight: | ||
| 206 | - destination = Size( | ||
| 207 | - input.width * (output.height / input.height), | ||
| 208 | - output.height, | ||
| 209 | - ); | ||
| 210 | - break; | ||
| 211 | - case BoxFit.none: | ||
| 212 | - destination = Size( | ||
| 213 | - math.min(input.width, output.width), | ||
| 214 | - math.min(input.height, output.height), | ||
| 215 | - ); | ||
| 216 | - break; | ||
| 217 | - case BoxFit.scaleDown: | ||
| 218 | - destination = input; | ||
| 219 | - if (destination.height > output.height) { | ||
| 220 | - destination = Size(output.height * inputAspectRatio, output.height); | ||
| 221 | - } | ||
| 222 | - if (destination.width > output.width) { | ||
| 223 | - destination = Size(output.width, output.width / inputAspectRatio); | ||
| 224 | - } | ||
| 225 | - break; | ||
| 226 | - } | ||
| 227 | - | ||
| 228 | - return destination; | ||
| 229 | -} |
| @@ -6,7 +6,6 @@ import 'package:flutter/cupertino.dart'; | @@ -6,7 +6,6 @@ import 'package:flutter/cupertino.dart'; | ||
| 6 | import 'package:flutter/foundation.dart'; | 6 | import 'package:flutter/foundation.dart'; |
| 7 | import 'package:flutter/services.dart'; | 7 | import 'package:flutter/services.dart'; |
| 8 | import 'package:mobile_scanner/mobile_scanner.dart'; | 8 | import 'package:mobile_scanner/mobile_scanner.dart'; |
| 9 | -import 'package:mobile_scanner/src/barcode_utility.dart'; | ||
| 10 | 9 | ||
| 11 | /// The [MobileScannerController] holds all the logic of this plugin, | 10 | /// The [MobileScannerController] holds all the logic of this plugin, |
| 12 | /// where as the [MobileScanner] class is the frontend of this plugin. | 11 | /// where as the [MobileScanner] class is the frontend of this plugin. |
| @@ -287,14 +286,26 @@ class MobileScannerController { | @@ -287,14 +286,26 @@ class MobileScannerController { | ||
| 287 | torchState.value = TorchState.on; | 286 | torchState.value = TorchState.on; |
| 288 | } | 287 | } |
| 289 | 288 | ||
| 289 | + final Size size; | ||
| 290 | + | ||
| 291 | + if (kIsWeb) { | ||
| 292 | + size = Size( | ||
| 293 | + startResult['videoWidth'] as double? ?? 0, | ||
| 294 | + startResult['videoHeight'] as double? ?? 0, | ||
| 295 | + ); | ||
| 296 | + } else { | ||
| 297 | + final Map<Object?, Object?>? sizeInfo = | ||
| 298 | + startResult['size'] as Map<Object?, Object?>?; | ||
| 299 | + | ||
| 300 | + size = Size( | ||
| 301 | + sizeInfo?['width'] as double? ?? 0, | ||
| 302 | + sizeInfo?['height'] as double? ?? 0, | ||
| 303 | + ); | ||
| 304 | + } | ||
| 305 | + | ||
| 290 | isStarting = false; | 306 | isStarting = false; |
| 291 | return startArguments.value = MobileScannerArguments( | 307 | return startArguments.value = MobileScannerArguments( |
| 292 | - size: kIsWeb | ||
| 293 | - ? Size( | ||
| 294 | - startResult['videoWidth'] as double? ?? 0, | ||
| 295 | - startResult['videoHeight'] as double? ?? 0, | ||
| 296 | - ) | ||
| 297 | - : toSize(startResult['size'] as Map? ?? {}), | 308 | + size: size, |
| 298 | hasTorch: hasTorch, | 309 | hasTorch: hasTorch, |
| 299 | textureId: kIsWeb ? null : startResult['textureId'] as int?, | 310 | textureId: kIsWeb ? null : startResult['textureId'] as int?, |
| 300 | webId: kIsWeb ? startResult['ViewID'] as String? : null, | 311 | webId: kIsWeb ? startResult['ViewID'] as String? : null, |
| @@ -424,7 +435,9 @@ class MobileScannerController { | @@ -424,7 +435,9 @@ class MobileScannerController { | ||
| 424 | barcodes: [ | 435 | barcodes: [ |
| 425 | Barcode( | 436 | Barcode( |
| 426 | rawValue: (data as Map)['payload'] as String?, | 437 | rawValue: (data as Map)['payload'] as String?, |
| 427 | - format: toFormat(data['symbology'] as int), | 438 | + format: BarcodeFormat.fromRawValue( |
| 439 | + data['symbology'] as int? ?? -1, | ||
| 440 | + ), | ||
| 428 | ), | 441 | ), |
| 429 | ], | 442 | ], |
| 430 | ), | 443 | ), |
| @@ -432,6 +445,8 @@ class MobileScannerController { | @@ -432,6 +445,8 @@ class MobileScannerController { | ||
| 432 | break; | 445 | break; |
| 433 | case 'barcodeWeb': | 446 | case 'barcodeWeb': |
| 434 | final barcode = data as Map?; | 447 | final barcode = data as Map?; |
| 448 | + final corners = barcode?['corners'] as List<Object?>? ?? <Object?>[]; | ||
| 449 | + | ||
| 435 | _barcodesController.add( | 450 | _barcodesController.add( |
| 436 | BarcodeCapture( | 451 | BarcodeCapture( |
| 437 | raw: data, | 452 | raw: data, |
| @@ -440,12 +455,16 @@ class MobileScannerController { | @@ -440,12 +455,16 @@ class MobileScannerController { | ||
| 440 | Barcode( | 455 | Barcode( |
| 441 | rawValue: barcode['rawValue'] as String?, | 456 | rawValue: barcode['rawValue'] as String?, |
| 442 | rawBytes: barcode['rawBytes'] as Uint8List?, | 457 | rawBytes: barcode['rawBytes'] as Uint8List?, |
| 443 | - format: toFormat(barcode['format'] as int), | ||
| 444 | - corners: toCorners( | ||
| 445 | - (barcode['corners'] as List<Object?>? ?? []) | ||
| 446 | - .cast<Map<Object?, Object?>>(), | ||
| 447 | - ) ?? | ||
| 448 | - const <Offset>[], | 458 | + format: BarcodeFormat.fromRawValue( |
| 459 | + barcode['format'] as int? ?? -1, | ||
| 460 | + ), | ||
| 461 | + corners: List.unmodifiable( | ||
| 462 | + corners.cast<Map<Object?, Object?>>().map( | ||
| 463 | + (Map<Object?, Object?> e) { | ||
| 464 | + return Offset(e['x']! as double, e['y']! as double); | ||
| 465 | + }, | ||
| 466 | + ), | ||
| 467 | + ), | ||
| 449 | ), | 468 | ), |
| 450 | ], | 469 | ], |
| 451 | ), | 470 | ), |
-
Please register or login to post a comment