From c36768dad87334d7c985bd52f8de5d1717fad321 Mon Sep 17 00:00:00 2001 From: Navaron Bracke Date: Sat, 4 Jan 2025 21:49:46 +0100 Subject: [PATCH 1/2] remove unused child argument --- CHANGELOG.md | 2 ++ example/lib/barcode_scanner_controller.dart | 2 +- example/lib/barcode_scanner_pageview.dart | 2 +- .../lib/barcode_scanner_returning_image.dart | 2 +- example/lib/barcode_scanner_window.dart | 2 +- example/lib/barcode_scanner_zoom.dart | 2 +- example/lib/mobile_scanner_overlay.dart | 2 +- lib/src/mobile_scanner.dart | 19 +++++-------------- 8 files changed, 13 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fd449106..e6e100317 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 7f906c6ca..c61fe031c 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, diff --git a/example/lib/barcode_scanner_pageview.dart b/example/lib/barcode_scanner_pageview.dart index 83f5fc66a..5182d0a09 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); }, ), diff --git a/example/lib/barcode_scanner_returning_image.dart b/example/lib/barcode_scanner_returning_image.dart index f8b007546..34f9138eb 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, diff --git a/example/lib/barcode_scanner_window.dart b/example/lib/barcode_scanner_window.dart index 9ff493adb..828a9c35e 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); }, ), diff --git a/example/lib/barcode_scanner_zoom.dart b/example/lib/barcode_scanner_zoom.dart index 09b11d690..9842be95b 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); }, ), diff --git a/example/lib/mobile_scanner_overlay.dart b/example/lib/mobile_scanner_overlay.dart index 402736785..cc42d5dc0 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/lib/src/mobile_scanner.dart b/lib/src/mobile_scanner.dart index cb6f0a778..336e03125 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( From 2a53d90e6d91fe23751f2a7d426c0d4920a91775 Mon Sep 17 00:00:00 2001 From: Navaron Bracke Date: Sat, 4 Jan 2025 22:04:12 +0100 Subject: [PATCH 2/2] fix analysis errors --- example/lib/barcode_scanner_controller.dart | 2 +- example/lib/barcode_scanner_pageview.dart | 2 +- example/lib/barcode_scanner_returning_image.dart | 2 +- example/lib/barcode_scanner_simple.dart | 2 +- example/lib/barcode_scanner_window.dart | 2 +- example/lib/barcode_scanner_zoom.dart | 2 +- example/lib/scanner_error_widget.dart | 1 - 7 files changed, 6 insertions(+), 7 deletions(-) diff --git a/example/lib/barcode_scanner_controller.dart b/example/lib/barcode_scanner_controller.dart index c61fe031c..7590482fd 100644 --- a/example/lib/barcode_scanner_controller.dart +++ b/example/lib/barcode_scanner_controller.dart @@ -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 5182d0a09..a41082d24 100644 --- a/example/lib/barcode_scanner_pageview.dart +++ b/example/lib/barcode_scanner_pageview.dart @@ -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 34f9138eb..74e7ccc72 100644 --- a/example/lib/barcode_scanner_returning_image.dart +++ b/example/lib/barcode_scanner_returning_image.dart @@ -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 73168a370..33a0a3b6e 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 828a9c35e..a45106e23 100644 --- a/example/lib/barcode_scanner_window.dart +++ b/example/lib/barcode_scanner_window.dart @@ -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 9842be95b..7ecffbe47 100644 --- a/example/lib/barcode_scanner_zoom.dart +++ b/example/lib/barcode_scanner_zoom.dart @@ -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/scanner_error_widget.dart b/example/lib/scanner_error_widget.dart index fd16fbc3c..bbba3b0f3 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(