Browse Source

minor improvements

pull/82/head
Khoren Markosyan 2 years ago
parent
commit
e4cc6184b3
  1. 13
      example/lib/main.dart
  2. 32
      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
: const Duration(milliseconds: 500),
tryInverted: true,
actionButtonsAlignment: Alignment.bottomLeft,
),
if (showDebugInfo)
DebugInfoWidget(
@ -166,6 +165,12 @@ class _DemoPageState extends State<DemoPage> {
}
}
_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<DemoPage> {
failedScans = 0;
});
}
_onMultiScanModeChanged(bool isMultiScan) {
setState(() {
this.isMultiScan = isMultiScan;
});
}
}

32
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<ReaderWidget>
),
),
),
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);
},
),
],
);
}

9
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(

Loading…
Cancel
Save