Skip to content

Commit 85c654f

Browse files
committed
Refactor search input layout to improve semantics and maintainability
1 parent f09cc9f commit 85c654f

1 file changed

Lines changed: 153 additions & 150 deletions

File tree

lib/layouts/main_screen/main_search.dart

Lines changed: 153 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -111,164 +111,167 @@ class _MainSearchState extends State<MainSearch> {
111111
_foundEntries.isEmpty
112112
? const SizedBox(height: 16)
113113
: Container(),
114-
Row(
115-
mainAxisAlignment: MainAxisAlignment.center,
116-
children: [
117-
SizedBox(
118-
width: MediaQuery.of(context).size.width > 750
119-
? 600
120-
: MediaQuery.of(context).size.width - 50,
121-
child: TextField(
122-
decoration: InputDecoration(
123-
fillColor: Theme.of(context).canvasColor,
124-
filled: true,
125-
// border: const OutlineInputBorder(
126-
// borderSide: BorderSide(color: Colors.white)),
127-
contentPadding: _foundEntries.isEmpty
128-
? null
129-
: const EdgeInsets.only(
130-
bottom: -20.0,
131-
left: 12,
132-
right: 3,
133-
),
134-
hintText: suggestion != null
135-
? suggestion!.name
136-
: AppLocalizations.of(
137-
context,
138-
)!
139-
.enterASearchTerm,
140-
prefixIcon: _foundEntries.isEmpty
141-
? const Icon(
142-
Icons.search,
143-
color: Colors.grey,
144-
)
145-
: null,
146-
suffix: _foundEntries.isEmpty
147-
? null
148-
: IconButton(
149-
iconSize: 14,
150-
splashRadius: 14,
151-
icon: const Icon(Icons.clear),
152-
onPressed: () => clear(minimze: false),
153-
padding: EdgeInsets.zero,
154-
tooltip: AppLocalizations.of(
155-
context,
156-
)!
157-
.clear,
158-
),
159-
),
160-
style: Theme.of(context).textTheme.bodyMedium,
161-
cursorColor: MintY.currentColor,
162-
controller: searchBarController,
163-
autofocus: true,
164-
onChanged: (value) => _runFilter(value),
165-
onSubmitted: (value) {
166-
if (_foundEntries.isNotEmpty) {
167-
ActionHandler.handleActionEntry(
168-
_foundEntries[selectedIndex],
169-
clear,
170-
context,
171-
);
172-
} else if (suggestion != null) {
173-
ActionHandler.handleActionEntry(
174-
suggestion!,
175-
clear,
176-
context,
177-
);
178-
}
179-
},
180-
),
181-
),
182-
_foundEntries.isEmpty
183-
? Container()
184-
: const SizedBox(width: 10),
185-
_foundEntries.isEmpty
186-
? Container()
187-
: MintYButton(
188-
textColor: listFolders
189-
? backgroundColor
190-
: MintY.currentColor,
191-
backgroundColor: listFolders
192-
? MintY.currentColor
193-
: backgroundColor,
194-
icon: Icons.folder,
195-
width: 40,
196-
tooltip: listFolders
197-
? AppLocalizations.of(
198-
context,
199-
)!
200-
.hideFolders
201-
: AppLocalizations.of(
202-
context,
203-
)!
204-
.showFolders,
205-
onPressed: () {
206-
setState(() {
207-
listFolders = !listFolders;
208-
_runFilter(_lastKeyword);
209-
});
210-
},
211-
),
212-
_foundEntries.isEmpty
213-
? Container()
214-
: const SizedBox(width: 10),
215-
_foundEntries.isEmpty
216-
? Container()
217-
: MintYButton(
218-
textColor: listPackageManagerActions
219-
? backgroundColor
220-
: MintY.currentColor,
221-
backgroundColor: listPackageManagerActions
222-
? MintY.currentColor
223-
: backgroundColor,
224-
icon: Icons.archive,
225-
width: 40,
226-
tooltip: listPackageManagerActions
227-
? AppLocalizations.of(
228-
context,
229-
)!
230-
.hidePackageManagerActions
114+
ExcludeSemantics(
115+
child: Row(
116+
mainAxisAlignment: MainAxisAlignment.center,
117+
children: [
118+
SizedBox(
119+
width: MediaQuery.of(context).size.width > 750
120+
? 600
121+
: MediaQuery.of(context).size.width - 50,
122+
child: TextField(
123+
decoration: InputDecoration(
124+
fillColor: Theme.of(context).canvasColor,
125+
filled: true,
126+
// border: const OutlineInputBorder(
127+
// borderSide: BorderSide(color: Colors.white)),
128+
contentPadding: _foundEntries.isEmpty
129+
? null
130+
: const EdgeInsets.only(
131+
bottom: -20.0,
132+
left: 12,
133+
right: 3,
134+
),
135+
hintText: suggestion != null
136+
? suggestion!.name
231137
: AppLocalizations.of(
232138
context,
233139
)!
234-
.showPackageManagerActions,
235-
onPressed: () {
236-
setState(() {
237-
listPackageManagerActions =
238-
!listPackageManagerActions;
239-
_runFilter(_lastKeyword);
240-
});
241-
},
140+
.enterASearchTerm,
141+
prefixIcon: _foundEntries.isEmpty
142+
? const Icon(
143+
Icons.search,
144+
color: Colors.grey,
145+
)
146+
: null,
147+
suffix: _foundEntries.isEmpty
148+
? null
149+
: IconButton(
150+
iconSize: 14,
151+
splashRadius: 14,
152+
icon: const Icon(Icons.clear),
153+
onPressed: () =>
154+
clear(minimze: false),
155+
padding: EdgeInsets.zero,
156+
tooltip: AppLocalizations.of(
157+
context,
158+
)!
159+
.clear,
160+
),
242161
),
243-
_foundEntries.isEmpty
244-
? Container()
245-
: const SizedBox(width: 10),
246-
_foundEntries.isEmpty
247-
? Container()
248-
: IconButton(
249-
iconSize: 24,
250-
splashRadius: 24,
251-
icon: Icon(
252-
Icons.feedback,
253-
color: widget.colorfulBackground
254-
? Colors.white
255-
: Theme.of(
162+
style: Theme.of(context).textTheme.bodyMedium,
163+
cursorColor: MintY.currentColor,
164+
controller: searchBarController,
165+
autofocus: true,
166+
onChanged: (value) => _runFilter(value),
167+
onSubmitted: (value) {
168+
if (_foundEntries.isNotEmpty) {
169+
ActionHandler.handleActionEntry(
170+
_foundEntries[selectedIndex],
171+
clear,
172+
context,
173+
);
174+
} else if (suggestion != null) {
175+
ActionHandler.handleActionEntry(
176+
suggestion!,
177+
clear,
178+
context,
179+
);
180+
}
181+
},
182+
),
183+
),
184+
_foundEntries.isEmpty
185+
? Container()
186+
: const SizedBox(width: 10),
187+
_foundEntries.isEmpty
188+
? Container()
189+
: MintYButton(
190+
textColor: listFolders
191+
? backgroundColor
192+
: MintY.currentColor,
193+
backgroundColor: listFolders
194+
? MintY.currentColor
195+
: backgroundColor,
196+
icon: Icons.folder,
197+
width: 40,
198+
tooltip: listFolders
199+
? AppLocalizations.of(
256200
context,
257-
).textTheme.displayLarge!.color,
201+
)!
202+
.hideFolders
203+
: AppLocalizations.of(
204+
context,
205+
)!
206+
.showFolders,
207+
onPressed: () {
208+
setState(() {
209+
listFolders = !listFolders;
210+
_runFilter(_lastKeyword);
211+
});
212+
},
258213
),
259-
onPressed: () => showDialog(
260-
context: context,
261-
builder: (context) => FeedbackDialog(
262-
calledFromHome: false,
263-
foundEntries: _foundEntries,
264-
searchText: _lastKeyword,
214+
_foundEntries.isEmpty
215+
? Container()
216+
: const SizedBox(width: 10),
217+
_foundEntries.isEmpty
218+
? Container()
219+
: MintYButton(
220+
textColor: listPackageManagerActions
221+
? backgroundColor
222+
: MintY.currentColor,
223+
backgroundColor: listPackageManagerActions
224+
? MintY.currentColor
225+
: backgroundColor,
226+
icon: Icons.archive,
227+
width: 40,
228+
tooltip: listPackageManagerActions
229+
? AppLocalizations.of(
230+
context,
231+
)!
232+
.hidePackageManagerActions
233+
: AppLocalizations.of(
234+
context,
235+
)!
236+
.showPackageManagerActions,
237+
onPressed: () {
238+
setState(() {
239+
listPackageManagerActions =
240+
!listPackageManagerActions;
241+
_runFilter(_lastKeyword);
242+
});
243+
},
244+
),
245+
_foundEntries.isEmpty
246+
? Container()
247+
: const SizedBox(width: 10),
248+
_foundEntries.isEmpty
249+
? Container()
250+
: IconButton(
251+
iconSize: 24,
252+
splashRadius: 24,
253+
icon: Icon(
254+
Icons.feedback,
255+
color: widget.colorfulBackground
256+
? Colors.white
257+
: Theme.of(
258+
context,
259+
).textTheme.displayLarge!.color,
260+
),
261+
onPressed: () => showDialog(
262+
context: context,
263+
builder: (context) => FeedbackDialog(
264+
calledFromHome: false,
265+
foundEntries: _foundEntries,
266+
searchText: _lastKeyword,
267+
),
265268
),
269+
padding: EdgeInsets.zero,
270+
tooltip: AppLocalizations.of(context)!
271+
.sendFeedback,
266272
),
267-
padding: EdgeInsets.zero,
268-
tooltip: AppLocalizations.of(context)!
269-
.sendFeedback,
270-
),
271-
],
273+
],
274+
),
272275
),
273276
_foundEntries.isEmpty
274277
? const SizedBox(height: 50)

0 commit comments

Comments
 (0)