162 lines
5.3 KiB
Dart
162 lines
5.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/material.dart' as material;
|
|
import 'package:fmassive/database.dart';
|
|
import 'package:fmassive/main.dart';
|
|
import 'package:fmassive/settings.dart';
|
|
import 'package:moor/moor.dart';
|
|
|
|
class SettingsPage extends StatelessWidget {
|
|
const SettingsPage({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return const Scaffold(
|
|
body: Center(
|
|
child: _SettingsPage(),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
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();
|
|
|
|
void reset() async {
|
|
var data = await db.select(db.settings).get();
|
|
if (data.isEmpty) await db.into(db.settings).insert(defaultSettings);
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
reset();
|
|
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(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: material.Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
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)));
|
|
},
|
|
),
|
|
TextField(
|
|
decoration: const InputDecoration(
|
|
labelText: 'Sound',
|
|
),
|
|
onChanged: (value) {
|
|
db
|
|
.update(db.settings)
|
|
.write(SettingsCompanion(sound: Value(value)));
|
|
},
|
|
),
|
|
TextField(
|
|
decoration: const InputDecoration(
|
|
labelText: 'Light Color',
|
|
),
|
|
onChanged: (value) {
|
|
db
|
|
.update(db.settings)
|
|
.write(SettingsCompanion(lightColor: Value(value)));
|
|
},
|
|
),
|
|
TextField(
|
|
decoration: const InputDecoration(
|
|
labelText: 'Dark Color',
|
|
),
|
|
onChanged: (value) {
|
|
db
|
|
.update(db.settings)
|
|
.write(SettingsCompanion(darkColor: Value(value)));
|
|
},
|
|
),
|
|
TextField(
|
|
decoration: const InputDecoration(
|
|
labelText: 'Date',
|
|
),
|
|
onChanged: (value) {
|
|
db
|
|
.update(db.settings)
|
|
.write(SettingsCompanion(date: Value(value)));
|
|
},
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}),
|
|
);
|
|
}
|
|
}
|