From 062f6c4c8cc6e6c5274862e413c98615e10ed1d4 Mon Sep 17 00:00:00 2001 From: Foti Dim Date: Tue, 10 Feb 2026 21:55:02 +0100 Subject: [PATCH] Add active filter count display and improve UI in ScannerScreen - Introduced a new method `_getActiveFilterCount` to calculate the number of active filters. - Updated the filter button to show a badge with the active filter count. - Changed the clear filter button icon for better clarity. - Enhanced the hint style in the scan filter widget for improved visibility. --- example/lib/home/scanner_screen.dart | 63 ++++++++++++------- .../lib/home/widgets/scan_filter_widget.dart | 5 +- 2 files changed, 45 insertions(+), 23 deletions(-) diff --git a/example/lib/home/scanner_screen.dart b/example/lib/home/scanner_screen.dart index 5430580..b3e738d 100644 --- a/example/lib/home/scanner_screen.dart +++ b/example/lib/home/scanner_screen.dart @@ -255,6 +255,15 @@ class _ScannerScreenState extends State { if (mounted) await _startScan(); } + int _getActiveFilterCount(ScanFilter? filter) { + if (filter == null) return 0; + int n = 0; + if (filter.withServices.isNotEmpty) n++; + if (filter.withNamePrefix.isNotEmpty) n++; + if (filter.withManufacturerData.isNotEmpty) n++; + return n; + } + void _showScanFilterBottomSheet() { showModalBottomSheet( isScrollControlled: true, @@ -657,32 +666,42 @@ class _ScannerScreenState extends State { ), ), const SizedBox(width: 4), - TextButton.icon( - onPressed: _showScanFilterBottomSheet, - icon: Icon( - scanFilter != null - ? Icons.filter_list - : Icons.filter_list_outlined, - size: 18, - color: scanFilter != null - ? colorScheme.primary - : colorScheme.onSurface, - ), + Badge( + isLabelVisible: _getActiveFilterCount(scanFilter) > 0, label: Text( - 'Filter', - style: TextStyle( - color: scanFilter != null - ? colorScheme.primary - : colorScheme.onSurface, - fontSize: 12, + '${_getActiveFilterCount(scanFilter)}', + style: const TextStyle( + fontSize: 10, fontWeight: FontWeight.w600, ), ), - style: TextButton.styleFrom( - padding: EdgeInsets.symmetric(horizontal: 8), - backgroundColor: scanFilter != null - ? colorScheme.primaryContainer - : null, + child: TextButton.icon( + onPressed: _showScanFilterBottomSheet, + icon: Icon( + scanFilter != null + ? Icons.filter_list + : Icons.filter_list_outlined, + size: 18, + color: scanFilter != null + ? colorScheme.primary + : colorScheme.onSurface, + ), + label: Text( + 'Filter', + style: TextStyle( + color: scanFilter != null + ? colorScheme.primary + : colorScheme.onSurface, + fontSize: 12, + fontWeight: FontWeight.w600, + ), + ), + style: TextButton.styleFrom( + padding: EdgeInsets.symmetric(horizontal: 8), + backgroundColor: scanFilter != null + ? colorScheme.primaryContainer + : null, + ), ), ), const Spacer(), diff --git a/example/lib/home/widgets/scan_filter_widget.dart b/example/lib/home/widgets/scan_filter_widget.dart index adfbc98..382ef9d 100644 --- a/example/lib/home/widgets/scan_filter_widget.dart +++ b/example/lib/home/widgets/scan_filter_widget.dart @@ -239,7 +239,7 @@ class _ScanFilterWidgetState extends State { flex: 2, child: OutlinedButton.icon( onPressed: clearFilter, - icon: const Icon(Icons.clear_all), + icon: const Icon(Icons.clear), label: const Text('Clear All'), style: OutlinedButton.styleFrom( foregroundColor: colorScheme.onSurface, @@ -328,6 +328,9 @@ class _ScanFilterWidgetState extends State { style: const TextStyle(fontFamily: 'monospace'), decoration: InputDecoration( hintText: hintText, + hintStyle: TextStyle( + color: colorScheme.onSurface.withValues(alpha: 0.15), + ), helperText: helperText, helperMaxLines: 2, helperStyle: TextStyle(