diff --git a/example/lib/main.dart b/example/lib/main.dart index 33926af..a95bb63 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -90,7 +90,6 @@ class _DemoPageState extends State { ? Duration.zero : const Duration(milliseconds: 500), tryInverted: true, - actionButtonsAlignment: Alignment.bottomLeft, ), if (showDebugInfo) DebugInfoWidget( @@ -166,6 +165,12 @@ class _DemoPageState extends State { } } + _onMultiScanModeChanged(bool isMultiScan) { + setState(() { + this.isMultiScan = isMultiScan; + }); + } + _showMessage(BuildContext context, String message) { ScaffoldMessenger.of(context).hideCurrentSnackBar(); ScaffoldMessenger.of(context).showSnackBar( @@ -179,10 +184,4 @@ class _DemoPageState extends State { failedScans = 0; }); } - - _onMultiScanModeChanged(bool isMultiScan) { - setState(() { - this.isMultiScan = isMultiScan; - }); - } } diff --git a/lib/src/ui/reader_widget.dart b/lib/src/ui/reader_widget.dart index cbfd92f..5a32a05 100644 --- a/lib/src/ui/reader_widget.dart +++ b/lib/src/ui/reader_widget.dart @@ -20,12 +20,14 @@ class ReaderWidget extends StatefulWidget { this.onControllerCreated, this.onMultiScanModeChanged, this.isMultiScan = false, + this.multiScanModeAlignment = Alignment.bottomRight, + this.multiScanModePadding = const EdgeInsets.all(10), this.codeFormat = Format.any, this.tryHarder = false, this.tryInverted = false, this.showScannerOverlay = true, this.scannerOverlay, - this.actionButtonsAlignment = Alignment.topCenter, + this.actionButtonsAlignment = Alignment.bottomLeft, this.actionButtonsPadding = const EdgeInsets.all(10), this.showFlashlight = true, this.showToggleCamera = true, @@ -55,11 +57,18 @@ class ReaderWidget extends StatefulWidget { final Function(CameraController?)? onControllerCreated; /// Called when the multi scan mode is changed + /// When set to null, the multi scan mode button will not be displayed final Function(bool)? onMultiScanModeChanged; /// Allow multiple scans final bool isMultiScan; + /// Alignment for multi scan mode button + final AlignmentGeometry multiScanModeAlignment; + + /// Padding for multi scan mode button + final EdgeInsetsGeometry multiScanModePadding; + /// Code format to scan final int codeFormat; @@ -395,15 +404,18 @@ class _ReaderWidgetState extends State ), ), ), - ScanModeDropdown( - isMultiScan: isMultiScan, - onChanged: (bool value) { - setState(() { - isMultiScan = value; - }); - widget.onMultiScanModeChanged?.call(value); - }, - ), + if (widget.onMultiScanModeChanged != null) + ScanModeDropdown( + isMultiScan: isMultiScan, + alignment: widget.multiScanModeAlignment, + padding: widget.multiScanModePadding, + onChanged: (bool value) { + setState(() { + isMultiScan = value; + }); + widget.onMultiScanModeChanged?.call(value); + }, + ), ], ); } diff --git a/lib/src/ui/scan_mode_dropdown.dart b/lib/src/ui/scan_mode_dropdown.dart index 0c4811f..468f6cc 100644 --- a/lib/src/ui/scan_mode_dropdown.dart +++ b/lib/src/ui/scan_mode_dropdown.dart @@ -5,17 +5,22 @@ class ScanModeDropdown extends StatelessWidget { super.key, this.isMultiScan = false, this.onChanged, + this.alignment = Alignment.bottomRight, + this.padding = const EdgeInsets.all(10), }); final bool isMultiScan; final Function(bool value)? onChanged; + final AlignmentGeometry alignment; + final EdgeInsetsGeometry padding; + @override Widget build(BuildContext context) { return Align( - alignment: Alignment.bottomRight, + alignment: alignment, child: Padding( - padding: const EdgeInsets.all(10), + padding: padding, child: Container( padding: const EdgeInsets.symmetric(horizontal: 10), decoration: BoxDecoration(