Skip to content

Commit

Permalink
Merge pull request #818 from navaronbracke/reorganise_classes
Browse files Browse the repository at this point in the history
feat: Move classes into their own files
  • Loading branch information
navaronbracke authored Oct 23, 2023
2 parents 68330a7 + 36b9f6b commit cabebb0
Show file tree
Hide file tree
Showing 18 changed files with 549 additions and 428 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## NEXT
Improvements:
* The `type` of an `Address` is now non-null.
* The `type` of an `Email` is now non-null.
* The `phoneNumber` of an `SMS` is now non-null.
* The `latitude` and `longitude` of a `GeoPoint` are now non-null.
* The `phones` and `urls` of `ContactInfo` are now non-null.
* The `url` of a `UrlBookmark` is now non-null.
* The `type` of `Phone` is now non-null.
* 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>`.

## 3.5.0
New Features:
* Added the option to switch between bundled and unbundled MLKit for Android. (thanks @woolfred !)
Expand Down
24 changes: 16 additions & 8 deletions example/lib/barcode_scanner_window.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:mobile_scanner/mobile_scanner.dart';

Expand Down Expand Up @@ -150,7 +151,10 @@ class BarcodeOverlay extends CustomPainter {

@override
void paint(Canvas canvas, Size size) {
if (barcode.corners == null) return;
if (barcode.corners.isEmpty) {
return;
}

final adjustedSize = applyBoxFit(boxFit, arguments.size, size);

double verticalPadding = size.height - adjustedSize.destination.height;
Expand All @@ -167,15 +171,19 @@ class BarcodeOverlay extends CustomPainter {
horizontalPadding = 0;
}

final ratioWidth =
(Platform.isIOS ? capture.width! : arguments.size.width) /
adjustedSize.destination.width;
final ratioHeight =
(Platform.isIOS ? capture.height! : arguments.size.height) /
adjustedSize.destination.height;
final double ratioWidth;
final double ratioHeight;

if (!kIsWeb && Platform.isIOS) {
ratioWidth = capture.size.width / adjustedSize.destination.width;
ratioHeight = capture.size.height / adjustedSize.destination.height;
} else {
ratioWidth = arguments.size.width / adjustedSize.destination.width;
ratioHeight = arguments.size.height / adjustedSize.destination.height;
}

final List<Offset> adjustedOffset = [];
for (final offset in barcode.corners!) {
for (final offset in barcode.corners) {
adjustedOffset.add(
Offset(
offset.dx / ratioWidth + horizontalPadding,
Expand Down
11 changes: 11 additions & 0 deletions lib/mobile_scanner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ export 'src/enums/torch_state.dart';
export 'src/mobile_scanner.dart';
export 'src/mobile_scanner_controller.dart';
export 'src/mobile_scanner_exception.dart';
export 'src/objects/address.dart';
export 'src/objects/barcode.dart';
export 'src/objects/barcode_capture.dart';
export 'src/objects/calendar_event.dart';
export 'src/objects/contact_info.dart';
export 'src/objects/driver_license.dart';
export 'src/objects/email.dart';
export 'src/objects/geo_point.dart';
export 'src/objects/mobile_scanner_arguments.dart';
export 'src/objects/person_name.dart';
export 'src/objects/phone.dart';
export 'src/objects/sms.dart';
export 'src/objects/url_bookmark.dart';
export 'src/objects/wifi.dart';
6 changes: 2 additions & 4 deletions lib/mobile_scanner_web_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ class MobileScannerWebPlugin {
_barCodeStreamSubscription =
barCodeReader.detectBarcodeContinuously().listen((code) {
if (code != null) {
final List<Offset>? corners = code.corners;

controller.add({
'name': 'barcodeWeb',
'data': {
Expand All @@ -140,8 +138,8 @@ class MobileScannerWebPlugin {
'format': code.format.rawValue,
'displayValue': code.displayValue,
'type': code.type.rawValue,
if (corners != null && corners.isNotEmpty)
'corners': corners
if (code.corners.isNotEmpty)
'corners': code.corners
.map(
(Offset c) => <Object?, Object?>{'x': c.dx, 'y': c.dy},
)
Expand Down
7 changes: 4 additions & 3 deletions lib/src/mobile_scanner_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,10 @@ class MobileScannerController {
rawBytes: barcode['rawBytes'] as Uint8List?,
format: toFormat(barcode['format'] as int),
corners: toCorners(
(barcode['corners'] as List<Object?>? ?? [])
.cast<Map<Object?, Object?>>(),
),
(barcode['corners'] as List<Object?>? ?? [])
.cast<Map<Object?, Object?>>(),
) ??
const <Offset>[],
),
],
),
Expand Down
33 changes: 33 additions & 0 deletions lib/src/objects/address.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:mobile_scanner/src/enums/address_type.dart';

/// An address.
class Address {
/// Creates a new [Address] instance.
const Address({
this.addressLines = const <String>[],
this.type = AddressType.unknown,
});

/// Creates a new [Address] instance from a map.
factory Address.fromNative(Map<Object?, Object?> data) {
final List<Object?>? addressLines = data['addressLines'] as List<Object?>?;
final AddressType type = AddressType.fromRawValue(
data['type'] as int? ?? 0,
);

if (addressLines == null) {
return Address(type: type);
}

return Address(
addressLines: List.unmodifiable(addressLines.cast<String>()),
type: type,
);
}

/// The address lines that represent this address.
final List<String> addressLines;

/// Gets type of the address.
final AddressType type;
}
Loading

0 comments on commit cabebb0

Please sign in to comment.