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.
This commit is contained in:
@@ -255,6 +255,15 @@ class _ScannerScreenState extends State<ScannerScreen> {
|
|||||||
if (mounted) await _startScan();
|
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() {
|
void _showScanFilterBottomSheet() {
|
||||||
showModalBottomSheet(
|
showModalBottomSheet(
|
||||||
isScrollControlled: true,
|
isScrollControlled: true,
|
||||||
@@ -657,32 +666,42 @@ class _ScannerScreenState extends State<ScannerScreen> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 4),
|
const SizedBox(width: 4),
|
||||||
TextButton.icon(
|
Badge(
|
||||||
onPressed: _showScanFilterBottomSheet,
|
isLabelVisible: _getActiveFilterCount(scanFilter) > 0,
|
||||||
icon: Icon(
|
|
||||||
scanFilter != null
|
|
||||||
? Icons.filter_list
|
|
||||||
: Icons.filter_list_outlined,
|
|
||||||
size: 18,
|
|
||||||
color: scanFilter != null
|
|
||||||
? colorScheme.primary
|
|
||||||
: colorScheme.onSurface,
|
|
||||||
),
|
|
||||||
label: Text(
|
label: Text(
|
||||||
'Filter',
|
'${_getActiveFilterCount(scanFilter)}',
|
||||||
style: TextStyle(
|
style: const TextStyle(
|
||||||
color: scanFilter != null
|
fontSize: 10,
|
||||||
? colorScheme.primary
|
|
||||||
: colorScheme.onSurface,
|
|
||||||
fontSize: 12,
|
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
style: TextButton.styleFrom(
|
child: TextButton.icon(
|
||||||
padding: EdgeInsets.symmetric(horizontal: 8),
|
onPressed: _showScanFilterBottomSheet,
|
||||||
backgroundColor: scanFilter != null
|
icon: Icon(
|
||||||
? colorScheme.primaryContainer
|
scanFilter != null
|
||||||
: 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(),
|
const Spacer(),
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ class _ScanFilterWidgetState extends State<ScanFilterWidget> {
|
|||||||
flex: 2,
|
flex: 2,
|
||||||
child: OutlinedButton.icon(
|
child: OutlinedButton.icon(
|
||||||
onPressed: clearFilter,
|
onPressed: clearFilter,
|
||||||
icon: const Icon(Icons.clear_all),
|
icon: const Icon(Icons.clear),
|
||||||
label: const Text('Clear All'),
|
label: const Text('Clear All'),
|
||||||
style: OutlinedButton.styleFrom(
|
style: OutlinedButton.styleFrom(
|
||||||
foregroundColor: colorScheme.onSurface,
|
foregroundColor: colorScheme.onSurface,
|
||||||
@@ -328,6 +328,9 @@ class _ScanFilterWidgetState extends State<ScanFilterWidget> {
|
|||||||
style: const TextStyle(fontFamily: 'monospace'),
|
style: const TextStyle(fontFamily: 'monospace'),
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: hintText,
|
hintText: hintText,
|
||||||
|
hintStyle: TextStyle(
|
||||||
|
color: colorScheme.onSurface.withValues(alpha: 0.15),
|
||||||
|
),
|
||||||
helperText: helperText,
|
helperText: helperText,
|
||||||
helperMaxLines: 2,
|
helperMaxLines: 2,
|
||||||
helperStyle: TextStyle(
|
helperStyle: TextStyle(
|
||||||
|
|||||||
Reference in New Issue
Block a user