2023-04-07 11:50:02 +12:00
|
|
|
import 'package:flutter/material.dart';
|
2023-04-09 14:39:41 +12:00
|
|
|
import 'package:flutter/material.dart' as material;
|
|
|
|
import 'package:fmassive/database.dart';
|
|
|
|
import 'package:fmassive/main.dart';
|
2023-04-13 15:10:09 +12:00
|
|
|
import 'package:fmassive/sound_picker.dart';
|
2023-04-09 14:39:41 +12:00
|
|
|
import 'package:moor/moor.dart';
|
2023-04-07 11:50:02 +12:00
|
|
|
|
|
|
|
class SettingsPage extends StatelessWidget {
|
2023-04-13 17:23:26 +12:00
|
|
|
const SettingsPage({super.key, required this.search});
|
|
|
|
|
|
|
|
final String search;
|
2023-04-07 11:50:02 +12:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-04-13 17:23:26 +12:00
|
|
|
return Scaffold(
|
2023-04-11 11:41:10 +12:00
|
|
|
body: Center(
|
2023-04-13 17:23:26 +12:00
|
|
|
child: _SettingsPage(search: search),
|
2023-04-07 11:50:02 +12:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2023-04-09 14:39:41 +12:00
|
|
|
|
|
|
|
class _SettingsPage extends StatefulWidget {
|
2023-04-13 17:23:26 +12:00
|
|
|
const _SettingsPage({Key? key, required this.search}) : super(key: key);
|
|
|
|
|
|
|
|
final String search;
|
2023-04-09 14:39:41 +12:00
|
|
|
|
|
|
|
@override
|
|
|
|
createState() => _SettingsPageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _SettingsPageState extends State<_SettingsPage> {
|
|
|
|
late Stream<Setting> stream;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
stream = db.select(db.settings).watchSingle();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
body: StreamBuilder<Setting>(
|
2023-04-13 17:23:26 +12:00
|
|
|
stream: stream,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
final settings = snapshot.data;
|
2023-04-09 14:39:41 +12:00
|
|
|
|
2023-04-13 17:23:26 +12:00
|
|
|
if (settings == null)
|
|
|
|
return const Center(child: CircularProgressIndicator());
|
2023-04-09 14:39:41 +12:00
|
|
|
|
2023-04-13 17:23:26 +12:00
|
|
|
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: [
|
|
|
|
Expanded(
|
|
|
|
child: ListView.builder(
|
|
|
|
itemCount: filteredItems.length,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
final item = filteredItems[index];
|
|
|
|
|
|
|
|
if (item['title'] == 'Sound') {
|
|
|
|
return Center(
|
|
|
|
child: SoundPicker(
|
2023-04-13 15:10:09 +12:00
|
|
|
path: settings.sound,
|
|
|
|
onSelect: (path) {
|
|
|
|
db
|
|
|
|
.update(db.settings)
|
|
|
|
.write(SettingsCompanion(sound: Value(path)));
|
2023-04-13 17:23:26 +12:00
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2023-04-09 14:39:41 +12:00
|
|
|
),
|
2023-04-13 17:23:26 +12:00
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2023-04-09 14:39:41 +12:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|