Skip to content

Commit 137466e

Browse files
Merge pull request #1272 from navaronbracke/placeholder_child
fix: remove unused child argument
2 parents 23360aa + 2a53d90 commit 137466e

10 files changed

+19
-27
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
* The `updateScanWindow` method is now private. Instead, update the scan window in the `MobileScanner` widget directly.
66
* The deprecated `EncryptionType.none` constant has been removed. Use `EncryptionType.unknown` instead.
7+
* The `errorBuilder` and `placeholderBuilder` of the `MobileScanner` widget no longer take a Widget argument, as it was unused.
8+
* The `MobileScannerErrorBuilder` typedef has been removed.
79

810
Bugs fixed:
911
* [Apple] Fixed an issue which caused the scanWindow to always be present, even when reset to no value.

example/lib/barcode_scanner_controller.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class _BarcodeScannerWithControllerState
5555
children: [
5656
MobileScanner(
5757
controller: controller,
58-
errorBuilder: (context, error, child) {
58+
errorBuilder: (context, error) {
5959
return ScannerErrorWidget(error: error);
6060
},
6161
fit: BoxFit.contain,
@@ -65,7 +65,7 @@ class _BarcodeScannerWithControllerState
6565
child: Container(
6666
alignment: Alignment.bottomCenter,
6767
height: 100,
68-
color: Colors.black.withOpacity(0.4),
68+
color: const Color.fromRGBO(0, 0, 0, 0.4),
6969
child: Row(
7070
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
7171
children: [

example/lib/barcode_scanner_pageview.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class _BarcodeScannerPage extends StatelessWidget {
6969
MobileScanner(
7070
controller: controller,
7171
fit: BoxFit.contain,
72-
errorBuilder: (context, error, child) {
72+
errorBuilder: (context, error) {
7373
return ScannerErrorWidget(error: error);
7474
},
7575
),
@@ -78,7 +78,7 @@ class _BarcodeScannerPage extends StatelessWidget {
7878
child: Container(
7979
alignment: Alignment.bottomCenter,
8080
height: 100,
81-
color: Colors.black.withOpacity(0.4),
81+
color: const Color.fromRGBO(0, 0, 0, 0.4),
8282
child: Center(
8383
child: ScannedBarcodeLabel(barcodes: controller.barcodes),
8484
),

example/lib/barcode_scanner_returning_image.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class _BarcodeScannerReturningImageState
8787
children: [
8888
MobileScanner(
8989
controller: controller,
90-
errorBuilder: (context, error, child) {
90+
errorBuilder: (context, error) {
9191
return ScannerErrorWidget(error: error);
9292
},
9393
fit: BoxFit.contain,
@@ -97,7 +97,7 @@ class _BarcodeScannerReturningImageState
9797
child: Container(
9898
alignment: Alignment.bottomCenter,
9999
height: 100,
100-
color: Colors.black.withOpacity(0.4),
100+
color: const Color.fromRGBO(0, 0, 0, 0.4),
101101
child: Row(
102102
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
103103
children: [

example/lib/barcode_scanner_simple.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class _BarcodeScannerSimpleState extends State<BarcodeScannerSimple> {
5050
child: Container(
5151
alignment: Alignment.bottomCenter,
5252
height: 100,
53-
color: Colors.black.withOpacity(0.4),
53+
color: const Color.fromRGBO(0, 0, 0, 0.4),
5454
child: Row(
5555
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
5656
children: [

example/lib/barcode_scanner_window.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class _BarcodeScannerWithScanWindowState
3939
fit: boxFit,
4040
scanWindow: scanWindow,
4141
controller: controller,
42-
errorBuilder: (context, error, child) {
42+
errorBuilder: (context, error) {
4343
return ScannerErrorWidget(error: error);
4444
},
4545
),
@@ -54,7 +54,7 @@ class _BarcodeScannerWithScanWindowState
5454
alignment: Alignment.center,
5555
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
5656
height: 100,
57-
color: Colors.black.withOpacity(0.4),
57+
color: const Color.fromRGBO(0, 0, 0, 0.4),
5858
child: ScannedBarcodeLabel(barcodes: controller.barcodes),
5959
),
6060
),

example/lib/barcode_scanner_zoom.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class _BarcodeScannerWithZoomState extends State<BarcodeScannerWithZoom> {
7777
MobileScanner(
7878
controller: controller,
7979
fit: BoxFit.contain,
80-
errorBuilder: (context, error, child) {
80+
errorBuilder: (context, error) {
8181
return ScannerErrorWidget(error: error);
8282
},
8383
),
@@ -86,7 +86,7 @@ class _BarcodeScannerWithZoomState extends State<BarcodeScannerWithZoom> {
8686
child: Container(
8787
alignment: Alignment.bottomCenter,
8888
height: 100,
89-
color: Colors.black.withOpacity(0.4),
89+
color: const Color.fromRGBO(0, 0, 0, 0.4),
9090
child: Column(
9191
children: [
9292
if (!kIsWeb) _buildZoomScaleSlider(),

example/lib/mobile_scanner_overlay.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class _BarcodeScannerWithOverlayState extends State<BarcodeScannerWithOverlay> {
3838
fit: BoxFit.contain,
3939
controller: controller,
4040
scanWindow: scanWindow,
41-
errorBuilder: (context, error, child) {
41+
errorBuilder: (context, error) {
4242
return ScannerErrorWidget(error: error);
4343
},
4444
overlayBuilder: (context, constraints) {

example/lib/scanner_error_widget.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class ScannerErrorWidget extends StatelessWidget {
1919
errorMessage = 'Scanning is unsupported on this device';
2020
default:
2121
errorMessage = 'Generic Error';
22-
break;
2322
}
2423

2524
return ColoredBox(

lib/src/mobile_scanner.dart

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ import 'package:mobile_scanner/src/objects/barcode_capture.dart';
88
import 'package:mobile_scanner/src/objects/mobile_scanner_state.dart';
99
import 'package:mobile_scanner/src/scan_window_calculation.dart';
1010

11-
/// The function signature for the error builder.
12-
typedef MobileScannerErrorBuilder = Widget Function(
13-
BuildContext,
14-
MobileScannerException,
15-
Widget?,
16-
);
17-
1811
/// This widget displays a live camera preview for the barcode scanner.
1912
class MobileScanner extends StatefulWidget {
2013
/// Create a new [MobileScanner] using the provided [controller].
@@ -50,7 +43,7 @@ class MobileScanner extends StatefulWidget {
5043
///
5144
/// If this is null, a black [ColoredBox],
5245
/// with a centered white [Icons.error] icon is used as error widget.
53-
final MobileScannerErrorBuilder? errorBuilder;
46+
final Widget Function(BuildContext, MobileScannerException)? errorBuilder;
5447

5548
/// The [BoxFit] for the camera preview.
5649
///
@@ -73,7 +66,7 @@ class MobileScanner extends StatefulWidget {
7366
/// If this is null, a black [ColoredBox] is used as placeholder.
7467
///
7568
/// The placeholder is displayed when the camera preview is being initialized.
76-
final Widget Function(BuildContext, Widget?)? placeholderBuilder;
69+
final WidgetBuilder? placeholderBuilder;
7770

7871
/// The scan window rectangle for the barcode scanner.
7972
///
@@ -203,12 +196,11 @@ class _MobileScannerState extends State<MobileScanner>
203196
Widget build(BuildContext context) {
204197
return ValueListenableBuilder<MobileScannerState>(
205198
valueListenable: controller,
206-
builder: (BuildContext context, MobileScannerState value, Widget? child) {
199+
builder: (BuildContext context, MobileScannerState value, _) {
207200
if (!value.isInitialized) {
208201
const Widget defaultPlaceholder = ColoredBox(color: Colors.black);
209202

210-
return widget.placeholderBuilder?.call(context, child) ??
211-
defaultPlaceholder;
203+
return widget.placeholderBuilder?.call(context) ?? defaultPlaceholder;
212204
}
213205

214206
final MobileScannerException? error = value.error;
@@ -219,8 +211,7 @@ class _MobileScannerState extends State<MobileScanner>
219211
child: Center(child: Icon(Icons.error, color: Colors.white)),
220212
);
221213

222-
return widget.errorBuilder?.call(context, error, child) ??
223-
defaultError;
214+
return widget.errorBuilder?.call(context, error) ?? defaultError;
224215
}
225216

226217
return LayoutBuilder(

0 commit comments

Comments
 (0)