Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove unused child argument #1272

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

withOpacity is deprecated, so I replaced it everywhere

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;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The linter now reports an obsolete break statement here

}

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(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that the function signature is short enough to fit on one line, I opted to remove the typedef

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;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reusing an exiting typedef from the framework here


/// 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, _) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users can create a child widget above the MobileScanner widget in their build method, which makes passing in a child widget redundant here. And as reported, the child parameter was unused, so it didn't add any value to the function signatures

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
Loading