Skip to content

Commit

Permalink
Merge pull request #1272 from navaronbracke/placeholder_child
Browse files Browse the repository at this point in the history
fix: remove unused child argument
  • Loading branch information
navaronbracke authored Jan 4, 2025
2 parents 23360aa + 2a53d90 commit 137466e
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 27 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions example/lib/barcode_scanner_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class _BarcodeScannerWithControllerState
children: [
MobileScanner(
controller: controller,
errorBuilder: (context, error, child) {
errorBuilder: (context, error) {
return ScannerErrorWidget(error: error);
},
fit: BoxFit.contain,
Expand All @@ -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: [
Expand Down
4 changes: 2 additions & 2 deletions example/lib/barcode_scanner_pageview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
),
Expand All @@ -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),
),
Expand Down
4 changes: 2 additions & 2 deletions example/lib/barcode_scanner_returning_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class _BarcodeScannerReturningImageState
children: [
MobileScanner(
controller: controller,
errorBuilder: (context, error, child) {
errorBuilder: (context, error) {
return ScannerErrorWidget(error: error);
},
fit: BoxFit.contain,
Expand All @@ -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: [
Expand Down
2 changes: 1 addition & 1 deletion example/lib/barcode_scanner_simple.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class _BarcodeScannerSimpleState extends State<BarcodeScannerSimple> {
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: [
Expand Down
4 changes: 2 additions & 2 deletions example/lib/barcode_scanner_window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class _BarcodeScannerWithScanWindowState
fit: boxFit,
scanWindow: scanWindow,
controller: controller,
errorBuilder: (context, error, child) {
errorBuilder: (context, error) {
return ScannerErrorWidget(error: error);
},
),
Expand All @@ -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),
),
),
Expand Down
4 changes: 2 additions & 2 deletions example/lib/barcode_scanner_zoom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class _BarcodeScannerWithZoomState extends State<BarcodeScannerWithZoom> {
MobileScanner(
controller: controller,
fit: BoxFit.contain,
errorBuilder: (context, error, child) {
errorBuilder: (context, error) {
return ScannerErrorWidget(error: error);
},
),
Expand All @@ -86,7 +86,7 @@ class _BarcodeScannerWithZoomState extends State<BarcodeScannerWithZoom> {
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(),
Expand Down
2 changes: 1 addition & 1 deletion example/lib/mobile_scanner_overlay.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class _BarcodeScannerWithOverlayState extends State<BarcodeScannerWithOverlay> {
fit: BoxFit.contain,
controller: controller,
scanWindow: scanWindow,
errorBuilder: (context, error, child) {
errorBuilder: (context, error) {
return ScannerErrorWidget(error: error);
},
overlayBuilder: (context, constraints) {
Expand Down
1 change: 0 additions & 1 deletion example/lib/scanner_error_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class ScannerErrorWidget extends StatelessWidget {
errorMessage = 'Scanning is unsupported on this device';
default:
errorMessage = 'Generic Error';
break;
}

return ColoredBox(
Expand Down
19 changes: 5 additions & 14 deletions lib/src/mobile_scanner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand Down Expand Up @@ -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.
///
Expand All @@ -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.
///
Expand Down Expand Up @@ -203,12 +196,11 @@ class _MobileScannerState extends State<MobileScanner>
Widget build(BuildContext context) {
return ValueListenableBuilder<MobileScannerState>(
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;
Expand All @@ -219,8 +211,7 @@ class _MobileScannerState extends State<MobileScanner>
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(
Expand Down

0 comments on commit 137466e

Please sign in to comment.