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();
|
||||||
|
@ -47,76 +49,84 @@ class _SettingsPageState extends State<_SettingsPage> {
|
||||||
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},
|
||||||
|
{'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: [
|
children: [
|
||||||
SwitchListTile(
|
Expanded(
|
||||||
title: const Text('Alarm'),
|
child: ListView.builder(
|
||||||
value: settings.alarm,
|
itemCount: filteredItems.length,
|
||||||
onChanged: (value) {
|
itemBuilder: (context, index) {
|
||||||
db
|
final item = filteredItems[index];
|
||||||
.update(db.settings)
|
|
||||||
.write(SettingsCompanion(alarm: Value(value)));
|
if (item['title'] == 'Sound') {
|
||||||
},
|
return Center(
|
||||||
),
|
|
||||||
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(
|
|
||||||
child: SoundPicker(
|
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