Add search to settings page
This commit is contained in:
		
							parent
							
								
									ea1cb1da76
								
							
						
					
					
						commit
						b58b877bb0
					
				|  | @ -42,7 +42,7 @@ class RootPage extends State<HomePage> { | ||||||
|   Widget getBody() { |   Widget getBody() { | ||||||
|     switch (routes[selected]['title']) { |     switch (routes[selected]['title']) { | ||||||
|       case 'Settings': |       case 'Settings': | ||||||
|         return const SettingsPage(); |         return SettingsPage(search: search); | ||||||
|       case 'Timer': |       case 'Timer': | ||||||
|         return const TimerPage(); |         return const TimerPage(); | ||||||
|       case 'Workouts': |       case 'Workouts': | ||||||
|  |  | ||||||
|  | @ -6,20 +6,24 @@ import 'package:fmassive/sound_picker.dart'; | ||||||
| import 'package:moor/moor.dart'; | import 'package:moor/moor.dart'; | ||||||
| 
 | 
 | ||||||
| class SettingsPage extends StatelessWidget { | class SettingsPage extends StatelessWidget { | ||||||
|   const SettingsPage({super.key}); |   const SettingsPage({super.key, required this.search}); | ||||||
|  | 
 | ||||||
|  |   final String search; | ||||||
| 
 | 
 | ||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|     return const Scaffold( |     return Scaffold( | ||||||
|       body: Center( |       body: Center( | ||||||
|         child: _SettingsPage(), |         child: _SettingsPage(search: search), | ||||||
|       ), |       ), | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| class _SettingsPage extends StatefulWidget { | class _SettingsPage extends StatefulWidget { | ||||||
|   const _SettingsPage({Key? key}) : super(key: key); |   const _SettingsPage({Key? key, required this.search}) : super(key: key); | ||||||
|  | 
 | ||||||
|  |   final String search; | ||||||
| 
 | 
 | ||||||
|   @override |   @override | ||||||
|   createState() => _SettingsPageState(); |   createState() => _SettingsPageState(); | ||||||
|  | @ -28,8 +32,6 @@ class _SettingsPage extends StatefulWidget { | ||||||
| class _SettingsPageState extends State<_SettingsPage> { | class _SettingsPageState extends State<_SettingsPage> { | ||||||
|   late Stream<Setting> stream; |   late Stream<Setting> stream; | ||||||
| 
 | 
 | ||||||
|   final TextEditingController searchController = TextEditingController(); |  | ||||||
| 
 |  | ||||||
|   @override |   @override | ||||||
|   void initState() { |   void initState() { | ||||||
|     super.initState(); |     super.initState(); | ||||||
|  | @ -40,83 +42,91 @@ class _SettingsPageState extends State<_SettingsPage> { | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|     return Scaffold( |     return Scaffold( | ||||||
|       body: StreamBuilder<Setting>( |       body: StreamBuilder<Setting>( | ||||||
|           stream: stream, |         stream: stream, | ||||||
|           builder: (context, snapshot) { |         builder: (context, snapshot) { | ||||||
|             final settings = snapshot.data; |           final settings = snapshot.data; | ||||||
| 
 | 
 | ||||||
|             if (settings == null) |           if (settings == null) | ||||||
|               return const Center(child: CircularProgressIndicator()); |             return const Center(child: CircularProgressIndicator()); | ||||||
| 
 | 
 | ||||||
|             return SingleChildScrollView( |           final filteredItems = [ | ||||||
|               child: material.Column( |             {'title': 'Alarm', 'value': settings.alarm}, | ||||||
|                 crossAxisAlignment: CrossAxisAlignment.start, |             {'title': 'Vibrate', 'value': settings.vibrate}, | ||||||
|                 children: [ |             {'title': 'Notify', 'value': settings.notify}, | ||||||
|                   SwitchListTile( |             {'title': 'Images', 'value': settings.images}, | ||||||
|                     title: const Text('Alarm'), |             {'title': 'Show Unit', 'value': settings.showUnit}, | ||||||
|                     value: settings.alarm, |             {'title': 'Steps', 'value': settings.steps}, | ||||||
|                     onChanged: (value) { |             {'title': 'Sound', 'value': settings.sound}, | ||||||
|                       db |           ] | ||||||
|                           .update(db.settings) |               .where((item) => (item['title'] as String) | ||||||
|                           .write(SettingsCompanion(alarm: Value(value))); |                   .toLowerCase() | ||||||
|                     }, |                   .contains(widget.search.toLowerCase())) | ||||||
|                   ), |               .toList(); | ||||||
|                   SwitchListTile( | 
 | ||||||
|                     title: const Text('Vibrate'), |           return material.Column( | ||||||
|                     value: settings.vibrate, |             children: [ | ||||||
|                     onChanged: (value) { |               Expanded( | ||||||
|                       db |                 child: ListView.builder( | ||||||
|                           .update(db.settings) |                   itemCount: filteredItems.length, | ||||||
|                           .write(SettingsCompanion(vibrate: Value(value))); |                   itemBuilder: (context, index) { | ||||||
|                     }, |                     final item = filteredItems[index]; | ||||||
|                   ), | 
 | ||||||
|                   SwitchListTile( |                     if (item['title'] == 'Sound') { | ||||||
|                     title: const Text('Notify'), |                       return Center( | ||||||
|                     value: settings.notify, |                         child: SoundPicker( | ||||||
|                     onChanged: (value) { |  | ||||||
|                       db |  | ||||||
|                           .update(db.settings) |  | ||||||
|                           .write(SettingsCompanion(notify: Value(value))); |  | ||||||
|                     }, |  | ||||||
|                   ), |  | ||||||
|                   SwitchListTile( |  | ||||||
|                     title: const Text('Images'), |  | ||||||
|                     value: settings.images, |  | ||||||
|                     onChanged: (value) { |  | ||||||
|                       db |  | ||||||
|                           .update(db.settings) |  | ||||||
|                           .write(SettingsCompanion(images: Value(value))); |  | ||||||
|                     }, |  | ||||||
|                   ), |  | ||||||
|                   SwitchListTile( |  | ||||||
|                     title: const Text('Show Unit'), |  | ||||||
|                     value: settings.showUnit, |  | ||||||
|                     onChanged: (value) { |  | ||||||
|                       db |  | ||||||
|                           .update(db.settings) |  | ||||||
|                           .write(SettingsCompanion(showUnit: Value(value))); |  | ||||||
|                     }, |  | ||||||
|                   ), |  | ||||||
|                   SwitchListTile( |  | ||||||
|                     title: const Text('Steps'), |  | ||||||
|                     value: settings.steps, |  | ||||||
|                     onChanged: (value) { |  | ||||||
|                       db |  | ||||||
|                           .update(db.settings) |  | ||||||
|                           .write(SettingsCompanion(steps: Value(value))); |  | ||||||
|                     }, |  | ||||||
|                   ), |  | ||||||
|                   Center( |  | ||||||
|                       child: SoundPicker( |  | ||||||
|                           path: settings.sound, |                           path: settings.sound, | ||||||
|                           onSelect: (path) { |                           onSelect: (path) { | ||||||
|                             db |                             db | ||||||
|                                 .update(db.settings) |                                 .update(db.settings) | ||||||
|                                 .write(SettingsCompanion(sound: Value(path))); |                                 .write(SettingsCompanion(sound: Value(path))); | ||||||
|                           })), |                           }, | ||||||
|                 ], |                         ), | ||||||
|  |                       ); | ||||||
|  |                     } | ||||||
|  | 
 | ||||||
|  |                     return SwitchListTile( | ||||||
|  |                       title: Text(item['title'].toString()), | ||||||
|  |                       value: item['value'] as bool, | ||||||
|  |                       onChanged: (value) { | ||||||
|  |                         switch (item['title']) { | ||||||
|  |                           case 'Alarm': | ||||||
|  |                             db | ||||||
|  |                                 .update(db.settings) | ||||||
|  |                                 .write(SettingsCompanion(alarm: Value(value))); | ||||||
|  |                             break; | ||||||
|  |                           case 'Vibrate': | ||||||
|  |                             db.update(db.settings).write( | ||||||
|  |                                 SettingsCompanion(vibrate: Value(value))); | ||||||
|  |                             break; | ||||||
|  |                           case 'Notify': | ||||||
|  |                             db | ||||||
|  |                                 .update(db.settings) | ||||||
|  |                                 .write(SettingsCompanion(notify: Value(value))); | ||||||
|  |                             break; | ||||||
|  |                           case 'Images': | ||||||
|  |                             db | ||||||
|  |                                 .update(db.settings) | ||||||
|  |                                 .write(SettingsCompanion(images: Value(value))); | ||||||
|  |                             break; | ||||||
|  |                           case 'Show Unit': | ||||||
|  |                             db.update(db.settings).write( | ||||||
|  |                                 SettingsCompanion(showUnit: Value(value))); | ||||||
|  |                             break; | ||||||
|  |                           case 'Steps': | ||||||
|  |                             db | ||||||
|  |                                 .update(db.settings) | ||||||
|  |                                 .write(SettingsCompanion(steps: Value(value))); | ||||||
|  |                             break; | ||||||
|  |                         } | ||||||
|  |                       }, | ||||||
|  |                     ); | ||||||
|  |                   }, | ||||||
|  |                 ), | ||||||
|               ), |               ), | ||||||
|             ); |             ], | ||||||
|           }), |           ); | ||||||
|  |         }, | ||||||
|  |       ), | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user