fmassive/lib/plans_page.dart

164 lines
5.3 KiB
Dart
Raw Normal View History

2023-04-07 11:50:02 +12:00
import 'package:flutter/material.dart';
2023-04-11 11:41:10 +12:00
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';
2023-04-07 11:50:02 +12:00
class PlansPage extends StatelessWidget {
const PlansPage({super.key});
@override
Widget build(BuildContext context) {
2023-04-11 11:41:10 +12:00
return const Scaffold(
body: Center(
child: _PlansPage(),
2023-04-07 11:50:02 +12:00
),
);
}
}
2023-04-11 11:41:10 +12:00
class _PlansPage extends StatefulWidget {
const _PlansPage({Key? key}) : super(key: key);
@override
createState() => _PlansPageState();
}
class _PlansPageState extends State<_PlansPage> {
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);
setState(() {
if (data.isEmpty) return;
});
}
@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(
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)));
},
),
],
),
);
}),
);
}
}