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-11 11:41:10 +12:00
|
|
|
const SettingsPage({super.key});
|
2023-04-07 11:50:02 +12:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-04-11 11:41:10 +12:00
|
|
|
return const Scaffold(
|
|
|
|
body: Center(
|
2023-04-09 14:39:41 +12:00
|
|
|
child: _SettingsPage(),
|
2023-04-07 11:50:02 +12:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2023-04-09 14:39:41 +12:00
|
|
|
|
|
|
|
class _SettingsPage extends StatefulWidget {
|
|
|
|
const _SettingsPage({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
createState() => _SettingsPageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _SettingsPageState extends State<_SettingsPage> {
|
|
|
|
late Stream<Setting> stream;
|
|
|
|
|
|
|
|
final TextEditingController searchController = TextEditingController();
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
stream = db.select(db.settings).watchSingle();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
body: StreamBuilder<Setting>(
|
|
|
|
stream: stream,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
final settings = snapshot.data;
|
|
|
|
|
|
|
|
if (settings == null)
|
|
|
|
return const Center(child: CircularProgressIndicator());
|
|
|
|
|
|
|
|
return SingleChildScrollView(
|
|
|
|
child: material.Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
SwitchListTile(
|
2023-04-09 14:44:06 +12:00
|
|
|
title: const Text('Alarm'),
|
2023-04-09 14:39:41 +12:00
|
|
|
value: settings.alarm,
|
|
|
|
onChanged: (value) {
|
|
|
|
db
|
|
|
|
.update(db.settings)
|
|
|
|
.write(SettingsCompanion(alarm: Value(value)));
|
|
|
|
},
|
|
|
|
),
|
|
|
|
SwitchListTile(
|
2023-04-09 14:44:06 +12:00
|
|
|
title: const Text('Vibrate'),
|
2023-04-09 14:39:41 +12:00
|
|
|
value: settings.vibrate,
|
|
|
|
onChanged: (value) {
|
|
|
|
db
|
|
|
|
.update(db.settings)
|
|
|
|
.write(SettingsCompanion(vibrate: Value(value)));
|
|
|
|
},
|
|
|
|
),
|
|
|
|
SwitchListTile(
|
2023-04-09 14:44:06 +12:00
|
|
|
title: const Text('Notify'),
|
2023-04-09 14:39:41 +12:00
|
|
|
value: settings.notify,
|
|
|
|
onChanged: (value) {
|
|
|
|
db
|
|
|
|
.update(db.settings)
|
|
|
|
.write(SettingsCompanion(notify: Value(value)));
|
|
|
|
},
|
|
|
|
),
|
|
|
|
SwitchListTile(
|
2023-04-09 14:44:06 +12:00
|
|
|
title: const Text('Images'),
|
2023-04-09 14:39:41 +12:00
|
|
|
value: settings.images,
|
|
|
|
onChanged: (value) {
|
|
|
|
db
|
|
|
|
.update(db.settings)
|
|
|
|
.write(SettingsCompanion(images: Value(value)));
|
|
|
|
},
|
|
|
|
),
|
|
|
|
SwitchListTile(
|
2023-04-09 14:44:06 +12:00
|
|
|
title: const Text('Show Unit'),
|
2023-04-09 14:39:41 +12:00
|
|
|
value: settings.showUnit,
|
|
|
|
onChanged: (value) {
|
|
|
|
db
|
|
|
|
.update(db.settings)
|
|
|
|
.write(SettingsCompanion(showUnit: Value(value)));
|
|
|
|
},
|
|
|
|
),
|
|
|
|
SwitchListTile(
|
2023-04-09 14:44:06 +12:00
|
|
|
title: const Text('Steps'),
|
2023-04-09 14:39:41 +12:00
|
|
|
value: settings.steps,
|
|
|
|
onChanged: (value) {
|
|
|
|
db
|
|
|
|
.update(db.settings)
|
|
|
|
.write(SettingsCompanion(steps: Value(value)));
|
|
|
|
},
|
|
|
|
),
|
2023-04-13 15:10:09 +12:00
|
|
|
Center(
|
|
|
|
child: SoundPicker(
|
|
|
|
path: settings.sound,
|
|
|
|
onSelect: (path) {
|
|
|
|
db
|
|
|
|
.update(db.settings)
|
|
|
|
.write(SettingsCompanion(sound: Value(path)));
|
|
|
|
})),
|
2023-04-09 14:39:41 +12:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|