Navaron Bracke

add size attribute to BarcodeCapture; make width/height of barcode capture non-null

@@ -7,6 +7,8 @@ Improvements: @@ -7,6 +7,8 @@ Improvements:
7 * The `phones` and `urls` of `ContactInfo` are now non-null. 7 * The `phones` and `urls` of `ContactInfo` are now non-null.
8 * The `url` of a `UrlBookmark` is now non-null. 8 * The `url` of a `UrlBookmark` is now non-null.
9 * The `type` of `Phone` is now non-null. 9 * The `type` of `Phone` is now non-null.
  10 +* The `width` and `height` of `BarcodeCapture` are now non-null.
  11 +* The `BarcodeCapture` class now exposes a `size`.
10 12
11 ## 3.5.0 13 ## 3.5.0
12 New Features: 14 New Features:
1 import 'dart:typed_data'; 1 import 'dart:typed_data';
  2 +import 'dart:ui';
2 3
3 import 'package:mobile_scanner/src/objects/barcode.dart'; 4 import 'package:mobile_scanner/src/objects/barcode.dart';
4 5
5 -/// The return object after a frame is scanned.  
6 -///  
7 -/// [barcodes] A list with barcodes. A scanned frame can contain multiple  
8 -/// barcodes.  
9 -/// [image] If enabled, an image of the scanned frame. 6 +/// This class represents a scanned barcode.
10 class BarcodeCapture { 7 class BarcodeCapture {
  8 + /// Create a new [BarcodeCapture] instance.
  9 + BarcodeCapture({
  10 + this.barcodes = const <Barcode>[],
  11 + double? height,
  12 + this.image,
  13 + this.raw,
  14 + double? width,
  15 + }) : size =
  16 + width == null && height == null ? Size.zero : Size(width!, height!);
  17 +
  18 + /// The list of scanned barcodes.
11 final List<Barcode> barcodes; 19 final List<Barcode> barcodes;
12 - final dynamic raw;  
13 20
  21 + /// The bytes of the image that is embedded in the barcode.
  22 + ///
  23 + /// This null if [MobileScannerController.returnImage] is false.
14 final Uint8List? image; 24 final Uint8List? image;
15 25
16 - final double? width; 26 + /// The raw data of the scanned barcode.
  27 + final dynamic raw; // TODO: this should be `Object?` instead of dynamic
17 28
18 - final double? height; 29 + /// The size of the scanned barcode.
  30 + final Size size;
19 31
20 - BarcodeCapture({  
21 - required this.barcodes,  
22 - required this.raw,  
23 - this.image,  
24 - this.width,  
25 - this.height,  
26 - }); 32 + /// The width of the scanned barcode.
  33 + ///
  34 + /// Prefer using `size.width` instead,
  35 + /// as this getter will be removed in the future.
  36 + double get width => size.width;
  37 +
  38 + /// The height of the scanned barcode.
  39 + ///
  40 + /// Prefer using `size.height` instead,
  41 + /// as this getter will be removed in the future.
  42 + double get height => size.height;
27 } 43 }