main
dart 43 lines 1.42 KB
Raw
1 import 'package:hugeicons/hugeicons.dart';
2 import 'package:flutter/material.dart';
3 import 'package:flutter_riverpod/flutter_riverpod.dart';
4 import 'package:localmind/l10n/app_localizations.dart';
5 import '../providers/model_picker_providers.dart';
6
7 class ModelSearchField extends ConsumerWidget {
8 const ModelSearchField({super.key});
9
10 @override
11 Widget build(BuildContext context, WidgetRef ref) {
12 final l10n = AppLocalizations.of(context)!;
13 final searchQuery = ref.watch(modelSearchQueryProvider);
14
15 return TextField(
16 decoration: InputDecoration(
17 hintText: l10n.search_models_hint,
18 prefixIcon: const Center(
19 widthFactor: 1.0,
20 heightFactor: 1.0,
21 child: HugeIcon(icon: HugeIcons.strokeRoundedSearch01, size: 20),
22 ),
23 isDense: true,
24 contentPadding: const EdgeInsets.symmetric(
25 horizontal: 12,
26 vertical: 10,
27 ),
28 border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
29 suffixIcon: searchQuery.isNotEmpty
30 ? IconButton(
31 icon: const HugeIcon(
32 icon: HugeIcons.strokeRoundedCancel01,
33 size: 18,
34 ),
35 onPressed: () =>
36 ref.read(modelSearchQueryProvider.notifier).clear(),
37 )
38 : null,
39 ),
40 onChanged: (q) => ref.read(modelSearchQueryProvider.notifier).setQuery(q),
41 );
42 }
43 }