@@ -26,94 +26,76 @@ class Filter {
26
26
int get hashCode => const ListEquality ().hash (terms);
27
27
}
28
28
29
- class FilterUI extends StatefulWidget {
29
+ class FilterUI extends StatelessWidget {
30
30
const FilterUI ({super .key});
31
31
32
32
@override
33
- State <FilterUI > createState () => _FilterUIState ();
34
- }
35
-
36
- class _FilterUIState extends State <FilterUI > {
37
- final controller = TextEditingController ();
38
-
39
- @override
40
- void dispose () {
41
- controller.dispose ();
42
- super .dispose ();
43
- }
33
+ Widget build (BuildContext context) {
34
+ final controller = TextEditingController ();
35
+ final results = context.watch <QueryResultsBase >();
36
+ final filter = results.filter;
44
37
45
- void _updateFilter (Iterable <String > newTerms) {
46
- final uri = GoRouter .of (context).routeInformationProvider.value.uri;
47
- final newUri = uri.replace (
48
- queryParameters: {...uri.queryParameters, 'filter' : newTerms.join (',' )},
49
- );
50
- GoRouter .of (context).go (newUri.toString ());
51
- }
38
+ void updateFilter (Iterable <String > newTerms) {
39
+ final uri = GoRouter .of (context).routeInformationProvider.value.uri;
40
+ final newUri = uri.replace (
41
+ queryParameters: {...uri.queryParameters, 'filter' : newTerms.join (',' )},
42
+ );
43
+ GoRouter .of (context).go (newUri.toString ());
44
+ }
52
45
53
- @override
54
- Widget build (BuildContext context) {
55
- return Consumer <QueryResultsBase >(
56
- builder: (context, results, child) {
57
- final filter = results.filter;
58
- return Column (
59
- crossAxisAlignment: CrossAxisAlignment .start,
60
- children: [
61
- ConstrainedBox (
62
- constraints: const BoxConstraints (maxHeight: 100.0 ),
63
- child: Scrollbar (
64
- child: SingleChildScrollView (
65
- child: Container (
66
- padding: const EdgeInsets .only (top: 16.0 ),
67
- alignment: Alignment .topLeft,
68
- child: Wrap (
69
- spacing: 8.0 ,
70
- runSpacing: 8.0 ,
71
- alignment: WrapAlignment .start,
72
- children: [
73
- for (final term in filter.terms)
74
- InputChip (
75
- label: Text (term),
76
- onDeleted: () {
77
- _updateFilter (
78
- filter.terms.where ((t) => t != term),
79
- );
80
- },
81
- onPressed: () {
82
- controller.text = term;
83
- },
84
- ),
85
- ],
86
- ),
87
- ),
46
+ return Column (
47
+ crossAxisAlignment: CrossAxisAlignment .start,
48
+ children: [
49
+ ConstrainedBox (
50
+ constraints: const BoxConstraints (maxHeight: 100.0 ),
51
+ child: Scrollbar (
52
+ child: SingleChildScrollView (
53
+ child: Container (
54
+ padding: const EdgeInsets .only (top: 16.0 ),
55
+ alignment: Alignment .topLeft,
56
+ child: Wrap (
57
+ spacing: 8.0 ,
58
+ runSpacing: 8.0 ,
59
+ alignment: WrapAlignment .start,
60
+ children: [
61
+ for (final term in filter.terms)
62
+ InputChip (
63
+ label: Text (term),
64
+ onDeleted: () {
65
+ updateFilter (filter.terms.where ((t) => t != term));
66
+ },
67
+ onPressed: () {
68
+ controller.text = term;
69
+ },
70
+ ),
71
+ ],
88
72
),
89
73
),
90
74
),
91
- SizedBox (
92
- width: 300.0 ,
93
- child: TextField (
94
- controller: controller,
95
- decoration: const InputDecoration (
96
- hintText: 'Test, configuration or experiment prefix' ,
97
- ),
98
- onSubmitted: (value) {
99
- if (value.trim ().isEmpty) return ;
100
- final newTerms = value.split (',' ).map ((s) => s.trim ());
101
- bool isNotReplacedByNewTerm (String term) => ! newTerms.any (
102
- (newTerm) =>
103
- term.startsWith (newTerm) || newTerm.startsWith (term),
104
- );
105
- controller.text = '' ;
106
- _updateFilter (
107
- filter.terms
108
- .where (isNotReplacedByNewTerm)
109
- .followedBy (newTerms),
110
- );
111
- },
112
- ),
75
+ ),
76
+ ),
77
+ SizedBox (
78
+ width: 300.0 ,
79
+ child: TextField (
80
+ controller: controller,
81
+ decoration: const InputDecoration (
82
+ hintText: 'Test, configuration or experiment prefix' ,
113
83
),
114
- ],
115
- );
116
- },
84
+ onSubmitted: (value) {
85
+ if (value.trim ().isEmpty) return ;
86
+ final newTerms = value.split (',' ).map ((s) => s.trim ());
87
+ bool isNotReplacedByNewTerm (String term) => ! newTerms.any (
88
+ (newTerm) =>
89
+ term.startsWith (newTerm) || newTerm.startsWith (term),
90
+ );
91
+ controller.text = '' ;
92
+ updateFilter (
93
+ filter.terms.where (isNotReplacedByNewTerm).followedBy (newTerms),
94
+ );
95
+ },
96
+ ),
97
+ ),
98
+ ],
117
99
);
118
100
}
119
101
}
0 commit comments