11import 'package:flutter/material.dart' ;
22import 'package:flutter/services.dart' ;
33import 'package:permission_handler/permission_handler.dart' ;
4- import 'package:pslab/colors.dart' ;
54import 'package:pslab/constants.dart' ;
65import 'package:pslab/view/widgets/applications_list_item.dart' ;
76import 'package:pslab/view/widgets/main_scaffold_widget.dart' ;
@@ -13,9 +12,8 @@ class InstrumentsScreen extends StatefulWidget {
1312}
1413
1514class _InstrumentsScreenState extends State <InstrumentsScreen > {
16- bool _showSearch = false ;
17- final TextEditingController _searchController = TextEditingController ();
1815 List <int > _filteredIndices = < int > [];
16+
1917 void _onItemTapped (int index) {
2018 switch (index) {
2119 case 0 :
@@ -116,186 +114,69 @@ class _InstrumentsScreenState extends State<InstrumentsScreen> {
116114 ]);
117115 }
118116
119- @override
120- void dispose () {
121- _searchController.dispose ();
122- super .dispose ();
123- }
124-
125117 @override
126118 Widget build (BuildContext context) {
127- return Scaffold (
128- body: MainScaffold (
129- index: 0 ,
130- title: instrumentsTitle,
131- body: SafeArea (
132- child: Column (
133- children: < Widget > [
134- AnimatedSwitcher (
135- duration: const Duration (milliseconds: 300 ),
136- child: _showSearch
137- ? Padding (
138- padding: const EdgeInsets .symmetric (
139- vertical: 8.0 , horizontal: 16.0 ),
140- child: Container (
141- decoration: BoxDecoration (
142- borderRadius: BorderRadius .circular (30.0 ),
143- boxShadow: const < BoxShadow > [
144- BoxShadow (
145- color: Color .fromRGBO (0 , 0 , 0 , 0.1 ),
146- blurRadius: 8 ,
147- offset: Offset (0 , 2 ),
148- ),
149- ],
119+ return MainScaffold (
120+ index: 0 ,
121+ title: instrumentsTitle,
122+ showSearch: true ,
123+ onSearchChanged: _filterInstruments,
124+ searchHint: searchInstrumentsHint,
125+ body: SafeArea (
126+ child: _filteredIndices.isEmpty
127+ ? Center (
128+ child: Column (
129+ mainAxisAlignment: MainAxisAlignment .center,
130+ children: < Widget > [
131+ Icon (
132+ Icons .search_off,
133+ size: 64 ,
134+ color: Theme .of (context)
135+ .colorScheme
136+ .onSurface
137+ .withAlpha (128 ),
138+ ),
139+ const SizedBox (height: 16 ),
140+ Text (
141+ noInstrumentsFoundMessage,
142+ style: Theme .of (context).textTheme.titleMedium? .copyWith (
143+ color: Theme .of (context)
144+ .colorScheme
145+ .onSurface
146+ .withAlpha (179 ),
150147 ),
151- child: TextField (
152- controller: _searchController,
153- onChanged: _filterInstruments,
154- decoration: InputDecoration (
155- hintText: searchInstrumentsHint,
156- hintStyle: TextStyle (
157- color: Theme .of (context)
158- .colorScheme
159- .onSurface
160- .withAlpha (153 ),
161- ),
162- prefixIcon: Icon (
163- Icons .search,
164- color: Theme .of (context)
165- .colorScheme
166- .onSurface
167- .withAlpha (179 ),
168- ),
169- suffixIcon: _searchController.text.isNotEmpty
170- ? IconButton (
171- icon: Icon (
172- Icons .clear,
173- color: Theme .of (context)
174- .colorScheme
175- .onSurface
176- .withAlpha (179 ),
177- ),
178- onPressed: () {
179- _searchController.clear ();
180- _filterInstruments ('' );
181- },
182- )
183- : null ,
184- border: OutlineInputBorder (
185- borderRadius: BorderRadius .circular (30.0 ),
186- borderSide: BorderSide .none,
187- ),
188- enabledBorder: OutlineInputBorder (
189- borderRadius: BorderRadius .circular (30.0 ),
190- borderSide: BorderSide (
191- color: primaryRed,
192- width: 1.5 ,
193- ),
194- ),
195- focusedBorder: OutlineInputBorder (
196- borderRadius: BorderRadius .circular (30.0 ),
197- borderSide: BorderSide (
198- color: primaryRed,
199- width: 2.5 ,
200- ),
201- ),
202- filled: true ,
203- fillColor: Theme .of (context).colorScheme.surface,
204- contentPadding: const EdgeInsets .symmetric (
205- horizontal: 20.0 ,
206- vertical: 16.0 ,
207- ),
208- ),
148+ ),
149+ const SizedBox (height: 8 ),
150+ Text (
151+ tryDifferentSearchSuggestion,
152+ style: Theme .of (context).textTheme.bodyMedium? .copyWith (
153+ color: Theme .of (context)
154+ .colorScheme
155+ .onSurface
156+ .withAlpha (128 ),
209157 ),
210- ),
211- )
212- : const SizedBox .shrink (key: ValueKey ('empty_space' )),
213- ),
214- Expanded (
215- child: _filteredIndices.isEmpty
216- ? Center (
217- child: Column (
218- mainAxisAlignment: MainAxisAlignment .center,
219- children: < Widget > [
220- Icon (
221- Icons .search_off,
222- size: 64 ,
223- color: Theme .of (context)
224- .colorScheme
225- .onSurface
226- .withAlpha (128 ),
227- ),
228- const SizedBox (height: 16 ),
229- Text (
230- noInstrumentsFoundMessage,
231- style: Theme .of (context)
232- .textTheme
233- .titleMedium
234- ? .copyWith (
235- color: Theme .of (context)
236- .colorScheme
237- .onSurface
238- .withAlpha (179 ),
239- ),
240- ),
241- const SizedBox (height: 8 ),
242- Text (
243- tryDifferentSearchSuggestion,
244- style: Theme .of (context)
245- .textTheme
246- .bodyMedium
247- ? .copyWith (
248- color: Theme .of (context)
249- .colorScheme
250- .onSurface
251- .withAlpha (128 ),
252- ),
253- ),
254- ],
255- ),
256- )
257- : ScrollConfiguration (
258- behavior: const ScrollBehavior (),
259- child: ListView .builder (
260- itemCount: _filteredIndices.length,
261- itemBuilder: (context, index) {
262- final int originalIndex = _filteredIndices[index];
263- return GestureDetector (
264- onTap: () => _onItemTapped (originalIndex),
265- child: ApplicationsListItem (
266- heading: instrumentHeadings[originalIndex],
267- description: instrumentDesc[originalIndex],
268- instrumentIcon: instrumentIcons[originalIndex],
269- ),
270- );
271- },
272- ),
158+ ),
159+ ],
160+ ),
161+ )
162+ : ScrollConfiguration (
163+ behavior: const ScrollBehavior (),
164+ child: ListView .builder (
165+ itemCount: _filteredIndices.length,
166+ itemBuilder: (context, index) {
167+ final int originalIndex = _filteredIndices[index];
168+ return GestureDetector (
169+ onTap: () => _onItemTapped (originalIndex),
170+ child: ApplicationsListItem (
171+ heading: instrumentHeadings[originalIndex],
172+ description: instrumentDesc[originalIndex],
173+ instrumentIcon: instrumentIcons[originalIndex],
273174 ),
175+ );
176+ },
177+ ),
274178 ),
275- ],
276- ),
277- ),
278- ),
279- floatingActionButton: FloatingActionButton (
280- onPressed: () {
281- setState (() {
282- _showSearch = ! _showSearch;
283- if (! _showSearch) {
284- _searchController.clear ();
285- _filterInstruments ('' );
286- }
287- });
288- },
289- shape: RoundedRectangleBorder (
290- borderRadius: BorderRadius .circular (50 ),
291- ),
292- backgroundColor: Colors .white,
293- child: Icon (
294- _showSearch ? Icons .close : Icons .search,
295- color: primaryRed,
296- ),
297179 ),
298- floatingActionButtonLocation: FloatingActionButtonLocation .endFloat,
299180 );
300181 }
301182}
0 commit comments