Browse Source

minor improvements

pull/82/head
Khoren Markosyan 2 years ago
parent
commit
e4cc6184b3
  1. 13
      example/lib/main.dart
  2. 14
      lib/src/ui/reader_widget.dart
  3. 9
      lib/src/ui/scan_mode_dropdown.dart

13
example/lib/main.dart

@ -90,7 +90,6 @@ class _DemoPageState extends State<DemoPage> {
? Duration.zero ? Duration.zero
: const Duration(milliseconds: 500), : const Duration(milliseconds: 500),
tryInverted: true, tryInverted: true,
actionButtonsAlignment: Alignment.bottomLeft,
), ),
if (showDebugInfo) if (showDebugInfo)
DebugInfoWidget( DebugInfoWidget(
@ -166,6 +165,12 @@ class _DemoPageState extends State<DemoPage> {
} }
} }
_onMultiScanModeChanged(bool isMultiScan) {
setState(() {
this.isMultiScan = isMultiScan;
});
}
_showMessage(BuildContext context, String message) { _showMessage(BuildContext context, String message) {
ScaffoldMessenger.of(context).hideCurrentSnackBar(); ScaffoldMessenger.of(context).hideCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
@ -179,10 +184,4 @@ class _DemoPageState extends State<DemoPage> {
failedScans = 0; failedScans = 0;
}); });
} }
_onMultiScanModeChanged(bool isMultiScan) {
setState(() {
this.isMultiScan = isMultiScan;
});
}
} }

14
lib/src/ui/reader_widget.dart

@ -20,12 +20,14 @@ class ReaderWidget extends StatefulWidget {
this.onControllerCreated, this.onControllerCreated,
this.onMultiScanModeChanged, this.onMultiScanModeChanged,
this.isMultiScan = false, this.isMultiScan = false,
this.multiScanModeAlignment = Alignment.bottomRight,
this.multiScanModePadding = const EdgeInsets.all(10),
this.codeFormat = Format.any, this.codeFormat = Format.any,
this.tryHarder = false, this.tryHarder = false,
this.tryInverted = false, this.tryInverted = false,
this.showScannerOverlay = true, this.showScannerOverlay = true,
this.scannerOverlay, this.scannerOverlay,
this.actionButtonsAlignment = Alignment.topCenter, this.actionButtonsAlignment = Alignment.bottomLeft,
this.actionButtonsPadding = const EdgeInsets.all(10), this.actionButtonsPadding = const EdgeInsets.all(10),
this.showFlashlight = true, this.showFlashlight = true,
this.showToggleCamera = true, this.showToggleCamera = true,
@ -55,11 +57,18 @@ class ReaderWidget extends StatefulWidget {
final Function(CameraController?)? onControllerCreated; final Function(CameraController?)? onControllerCreated;
/// Called when the multi scan mode is changed /// 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; final Function(bool)? onMultiScanModeChanged;
/// Allow multiple scans /// Allow multiple scans
final bool isMultiScan; 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 /// Code format to scan
final int codeFormat; final int codeFormat;
@ -395,8 +404,11 @@ class _ReaderWidgetState extends State<ReaderWidget>
), ),
), ),
), ),
if (widget.onMultiScanModeChanged != null)
ScanModeDropdown( ScanModeDropdown(
isMultiScan: isMultiScan, isMultiScan: isMultiScan,
alignment: widget.multiScanModeAlignment,
padding: widget.multiScanModePadding,
onChanged: (bool value) { onChanged: (bool value) {
setState(() { setState(() {
isMultiScan = value; isMultiScan = value;

9
lib/src/ui/scan_mode_dropdown.dart

@ -5,17 +5,22 @@ class ScanModeDropdown extends StatelessWidget {
super.key, super.key,
this.isMultiScan = false, this.isMultiScan = false,
this.onChanged, this.onChanged,
this.alignment = Alignment.bottomRight,
this.padding = const EdgeInsets.all(10),
}); });
final bool isMultiScan; final bool isMultiScan;
final Function(bool value)? onChanged; final Function(bool value)? onChanged;
final AlignmentGeometry alignment;
final EdgeInsetsGeometry padding;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Align( return Align(
alignment: Alignment.bottomRight, alignment: alignment,
child: Padding( child: Padding(
padding: const EdgeInsets.all(10), padding: padding,
child: Container( child: Container(
padding: const EdgeInsets.symmetric(horizontal: 10), padding: const EdgeInsets.symmetric(horizontal: 10),
decoration: BoxDecoration( decoration: BoxDecoration(

Loading…
Cancel
Save