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() {
|
||||
switch (routes[selected]['title']) {
|
||||
case 'Settings':
|
||||
return const SettingsPage();
|
||||
return SettingsPage(search: search);
|
||||
case 'Timer':
|
||||
return const TimerPage();
|
||||
case 'Workouts':
|
||||
|
|
|
@ -6,20 +6,24 @@ import 'package:fmassive/sound_picker.dart';
|
|||
import 'package:moor/moor.dart';
|
||||
|
||||
class SettingsPage extends StatelessWidget {
|
||||
const SettingsPage({super.key});
|
||||
const SettingsPage({super.key, required this.search});
|
||||
|
||||
final String search;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Scaffold(
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: _SettingsPage(),
|
||||
child: _SettingsPage(search: search),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
createState() => _SettingsPageState();
|
||||
|
@ -28,8 +32,6 @@ class _SettingsPage extends StatefulWidget {
|
|||
class _SettingsPageState extends State<_SettingsPage> {
|
||||
late Stream<Setting> stream;
|
||||
|
||||
final TextEditingController searchController = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
@ -47,76 +49,84 @@ class _SettingsPageState extends State<_SettingsPage> {
|
|||
if (settings == null)
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
|
||||
return SingleChildScrollView(
|
||||
child: material.Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
final filteredItems = [
|
||||
{'title': 'Alarm', 'value': settings.alarm},
|
||||
{'title': 'Vibrate', 'value': settings.vibrate},
|
||||
{'title': 'Notify', 'value': settings.notify},
|
||||
{'title': 'Images', 'value': settings.images},
|
||||
{'title': 'Show Unit', 'value': settings.showUnit},
|
||||
{'title': 'Steps', 'value': settings.steps},
|
||||
{'title': 'Sound', 'value': settings.sound},
|
||||
]
|
||||
.where((item) => (item['title'] as String)
|
||||
.toLowerCase()
|
||||
.contains(widget.search.toLowerCase()))
|
||||
.toList();
|
||||
|
||||
return material.Column(
|
||||
children: [
|
||||
SwitchListTile(
|
||||
title: const Text('Alarm'),
|
||||
value: settings.alarm,
|
||||
onChanged: (value) {
|
||||
db
|
||||
.update(db.settings)
|
||||
.write(SettingsCompanion(alarm: Value(value)));
|
||||
},
|
||||
),
|
||||
SwitchListTile(
|
||||
title: const Text('Vibrate'),
|
||||
value: settings.vibrate,
|
||||
onChanged: (value) {
|
||||
db
|
||||
.update(db.settings)
|
||||
.write(SettingsCompanion(vibrate: Value(value)));
|
||||
},
|
||||
),
|
||||
SwitchListTile(
|
||||
title: const Text('Notify'),
|
||||
value: settings.notify,
|
||||
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(
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: filteredItems.length,
|
||||
itemBuilder: (context, index) {
|
||||
final item = filteredItems[index];
|
||||
|
||||
if (item['title'] == 'Sound') {
|
||||
return Center(
|
||||
child: SoundPicker(
|
||||
path: settings.sound,
|
||||
onSelect: (path) {
|
||||
db
|
||||
.update(db.settings)
|
||||
.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