diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fd44910..e6e10031 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ * The `updateScanWindow` method is now private. Instead, update the scan window in the `MobileScanner` widget directly. * The deprecated `EncryptionType.none` constant has been removed. Use `EncryptionType.unknown` instead. +* The `errorBuilder` and `placeholderBuilder` of the `MobileScanner` widget no longer take a Widget argument, as it was unused. +* The `MobileScannerErrorBuilder` typedef has been removed. Bugs fixed: * [Apple] Fixed an issue which caused the scanWindow to always be present, even when reset to no value. diff --git a/example/lib/barcode_scanner_controller.dart b/example/lib/barcode_scanner_controller.dart index 7f906c6c..7590482f 100644 --- a/example/lib/barcode_scanner_controller.dart +++ b/example/lib/barcode_scanner_controller.dart @@ -55,7 +55,7 @@ class _BarcodeScannerWithControllerState children: [ MobileScanner( controller: controller, - errorBuilder: (context, error, child) { + errorBuilder: (context, error) { return ScannerErrorWidget(error: error); }, fit: BoxFit.contain, @@ -65,7 +65,7 @@ class _BarcodeScannerWithControllerState child: Container( alignment: Alignment.bottomCenter, height: 100, - color: Colors.black.withOpacity(0.4), + color: const Color.fromRGBO(0, 0, 0, 0.4), child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ diff --git a/example/lib/barcode_scanner_pageview.dart b/example/lib/barcode_scanner_pageview.dart index 83f5fc66..a41082d2 100644 --- a/example/lib/barcode_scanner_pageview.dart +++ b/example/lib/barcode_scanner_pageview.dart @@ -69,7 +69,7 @@ class _BarcodeScannerPage extends StatelessWidget { MobileScanner( controller: controller, fit: BoxFit.contain, - errorBuilder: (context, error, child) { + errorBuilder: (context, error) { return ScannerErrorWidget(error: error); }, ), @@ -78,7 +78,7 @@ class _BarcodeScannerPage extends StatelessWidget { child: Container( alignment: Alignment.bottomCenter, height: 100, - color: Colors.black.withOpacity(0.4), + color: const Color.fromRGBO(0, 0, 0, 0.4), child: Center( child: ScannedBarcodeLabel(barcodes: controller.barcodes), ), diff --git a/example/lib/barcode_scanner_returning_image.dart b/example/lib/barcode_scanner_returning_image.dart index f8b00754..74e7ccc7 100644 --- a/example/lib/barcode_scanner_returning_image.dart +++ b/example/lib/barcode_scanner_returning_image.dart @@ -87,7 +87,7 @@ class _BarcodeScannerReturningImageState children: [ MobileScanner( controller: controller, - errorBuilder: (context, error, child) { + errorBuilder: (context, error) { return ScannerErrorWidget(error: error); }, fit: BoxFit.contain, @@ -97,7 +97,7 @@ class _BarcodeScannerReturningImageState child: Container( alignment: Alignment.bottomCenter, height: 100, - color: Colors.black.withOpacity(0.4), + color: const Color.fromRGBO(0, 0, 0, 0.4), child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ diff --git a/example/lib/barcode_scanner_simple.dart b/example/lib/barcode_scanner_simple.dart index 73168a37..33a0a3b6 100644 --- a/example/lib/barcode_scanner_simple.dart +++ b/example/lib/barcode_scanner_simple.dart @@ -50,7 +50,7 @@ class _BarcodeScannerSimpleState extends State { child: Container( alignment: Alignment.bottomCenter, height: 100, - color: Colors.black.withOpacity(0.4), + color: const Color.fromRGBO(0, 0, 0, 0.4), child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ diff --git a/example/lib/barcode_scanner_window.dart b/example/lib/barcode_scanner_window.dart index 9ff493ad..a45106e2 100644 --- a/example/lib/barcode_scanner_window.dart +++ b/example/lib/barcode_scanner_window.dart @@ -39,7 +39,7 @@ class _BarcodeScannerWithScanWindowState fit: boxFit, scanWindow: scanWindow, controller: controller, - errorBuilder: (context, error, child) { + errorBuilder: (context, error) { return ScannerErrorWidget(error: error); }, ), @@ -54,7 +54,7 @@ class _BarcodeScannerWithScanWindowState alignment: Alignment.center, padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), height: 100, - color: Colors.black.withOpacity(0.4), + color: const Color.fromRGBO(0, 0, 0, 0.4), child: ScannedBarcodeLabel(barcodes: controller.barcodes), ), ), diff --git a/example/lib/barcode_scanner_zoom.dart b/example/lib/barcode_scanner_zoom.dart index 09b11d69..7ecffbe4 100644 --- a/example/lib/barcode_scanner_zoom.dart +++ b/example/lib/barcode_scanner_zoom.dart @@ -77,7 +77,7 @@ class _BarcodeScannerWithZoomState extends State { MobileScanner( controller: controller, fit: BoxFit.contain, - errorBuilder: (context, error, child) { + errorBuilder: (context, error) { return ScannerErrorWidget(error: error); }, ), @@ -86,7 +86,7 @@ class _BarcodeScannerWithZoomState extends State { child: Container( alignment: Alignment.bottomCenter, height: 100, - color: Colors.black.withOpacity(0.4), + color: const Color.fromRGBO(0, 0, 0, 0.4), child: Column( children: [ if (!kIsWeb) _buildZoomScaleSlider(), diff --git a/example/lib/mobile_scanner_overlay.dart b/example/lib/mobile_scanner_overlay.dart index 40273678..cc42d5dc 100644 --- a/example/lib/mobile_scanner_overlay.dart +++ b/example/lib/mobile_scanner_overlay.dart @@ -38,7 +38,7 @@ class _BarcodeScannerWithOverlayState extends State { fit: BoxFit.contain, controller: controller, scanWindow: scanWindow, - errorBuilder: (context, error, child) { + errorBuilder: (context, error) { return ScannerErrorWidget(error: error); }, overlayBuilder: (context, constraints) { diff --git a/example/lib/scanner_error_widget.dart b/example/lib/scanner_error_widget.dart index fd16fbc3..bbba3b0f 100644 --- a/example/lib/scanner_error_widget.dart +++ b/example/lib/scanner_error_widget.dart @@ -19,7 +19,6 @@ class ScannerErrorWidget extends StatelessWidget { errorMessage = 'Scanning is unsupported on this device'; default: errorMessage = 'Generic Error'; - break; } return ColoredBox( diff --git a/lib/src/mobile_scanner.dart b/lib/src/mobile_scanner.dart index cb6f0a77..336e0312 100644 --- a/lib/src/mobile_scanner.dart +++ b/lib/src/mobile_scanner.dart @@ -8,13 +8,6 @@ import 'package:mobile_scanner/src/objects/barcode_capture.dart'; import 'package:mobile_scanner/src/objects/mobile_scanner_state.dart'; import 'package:mobile_scanner/src/scan_window_calculation.dart'; -/// The function signature for the error builder. -typedef MobileScannerErrorBuilder = Widget Function( - BuildContext, - MobileScannerException, - Widget?, -); - /// This widget displays a live camera preview for the barcode scanner. class MobileScanner extends StatefulWidget { /// Create a new [MobileScanner] using the provided [controller]. @@ -50,7 +43,7 @@ class MobileScanner extends StatefulWidget { /// /// If this is null, a black [ColoredBox], /// with a centered white [Icons.error] icon is used as error widget. - final MobileScannerErrorBuilder? errorBuilder; + final Widget Function(BuildContext, MobileScannerException)? errorBuilder; /// The [BoxFit] for the camera preview. /// @@ -73,7 +66,7 @@ class MobileScanner extends StatefulWidget { /// If this is null, a black [ColoredBox] is used as placeholder. /// /// The placeholder is displayed when the camera preview is being initialized. - final Widget Function(BuildContext, Widget?)? placeholderBuilder; + final WidgetBuilder? placeholderBuilder; /// The scan window rectangle for the barcode scanner. /// @@ -203,12 +196,11 @@ class _MobileScannerState extends State Widget build(BuildContext context) { return ValueListenableBuilder( valueListenable: controller, - builder: (BuildContext context, MobileScannerState value, Widget? child) { + builder: (BuildContext context, MobileScannerState value, _) { if (!value.isInitialized) { const Widget defaultPlaceholder = ColoredBox(color: Colors.black); - return widget.placeholderBuilder?.call(context, child) ?? - defaultPlaceholder; + return widget.placeholderBuilder?.call(context) ?? defaultPlaceholder; } final MobileScannerException? error = value.error; @@ -219,8 +211,7 @@ class _MobileScannerState extends State child: Center(child: Icon(Icons.error, color: Colors.white)), ); - return widget.errorBuilder?.call(context, error, child) ?? - defaultError; + return widget.errorBuilder?.call(context, error) ?? defaultError; } return LayoutBuilder(