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';
|
|
|
|
import 'package:fmassive/settings.dart';
|
|
|
|
import 'package:moor/moor.dart';
|
2023-04-07 11:50:02 +12:00
|
|
|
|
|
|
|
class SettingsPage extends StatelessWidget {
|
2023-04-09 14:39:41 +12:00
|
|
|
SettingsPage({super.key});
|
|
|
|
|
|
|
|
final List<Map<String, dynamic>> routes = [
|
|
|
|
{'title': 'Home', 'icon': Icons.home},
|
|
|
|
{'title': 'Plans', 'icon': Icons.calendar_today},
|
|
|
|
{'title': 'Best', 'icon': Icons.star},
|
|
|
|
{'title': 'Workouts', 'icon': Icons.fitness_center},
|
|
|
|
{'title': 'Timer', 'icon': Icons.timer},
|
|
|
|
{'title': 'Settings', 'icon': Icons.settings},
|
|
|
|
];
|
2023-04-07 11:50:02 +12:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: const Text('Settings'),
|
|
|
|
),
|
2023-04-09 14:39:41 +12:00
|
|
|
drawer: Drawer(
|
|
|
|
child: ListView.builder(
|
|
|
|
itemCount: routes.length,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
return ListTile(
|
|
|
|
leading: Icon(routes[index]['icon']),
|
|
|
|
title: Text(routes[index]['title']),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.pop(context);
|
|
|
|
Navigator.pushNamed(
|
|
|
|
context, '/${routes[index]['title'].toLowerCase()}');
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
2023-04-07 11:50:02 +12:00
|
|
|
body: const 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();
|
|
|
|
|
|
|
|
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: Text('Alarm'),
|
|
|
|
value: settings.alarm,
|
|
|
|
onChanged: (value) {
|
|
|
|
db
|
|
|
|
.update(db.settings)
|
|
|
|
.write(SettingsCompanion(alarm: Value(value)));
|
|
|
|
},
|
|
|
|
),
|
|
|
|
SwitchListTile(
|
|
|
|
title: Text('Vibrate'),
|
|
|
|
value: settings.vibrate,
|
|
|
|
onChanged: (value) {
|
|
|
|
db
|
|
|
|
.update(db.settings)
|
|
|
|
.write(SettingsCompanion(vibrate: Value(value)));
|
|
|
|
},
|
|
|
|
),
|
|
|
|
SwitchListTile(
|
|
|
|
title: Text('Notify'),
|
|
|
|
value: settings.notify,
|
|
|
|
onChanged: (value) {
|
|
|
|
db
|
|
|
|
.update(db.settings)
|
|
|
|
.write(SettingsCompanion(notify: Value(value)));
|
|
|
|
},
|
|
|
|
),
|
|
|
|
SwitchListTile(
|
|
|
|
title: Text('Images'),
|
|
|
|
value: settings.images,
|
|
|
|
onChanged: (value) {
|
|
|
|
db
|
|
|
|
.update(db.settings)
|
|
|
|
.write(SettingsCompanion(images: Value(value)));
|
|
|
|
},
|
|
|
|
),
|
|
|
|
SwitchListTile(
|
|
|
|
title: Text('Show Unit'),
|
|
|
|
value: settings.showUnit,
|
|
|
|
onChanged: (value) {
|
|
|
|
db
|
|
|
|
.update(db.settings)
|
|
|
|
.write(SettingsCompanion(showUnit: Value(value)));
|
|
|
|
},
|
|
|
|
),
|
|
|
|
SwitchListTile(
|
|
|
|
title: Text('Steps'),
|
|
|
|
value: settings.steps,
|
|
|
|
onChanged: (value) {
|
|
|
|
db
|
|
|
|
.update(db.settings)
|
|
|
|
.write(SettingsCompanion(steps: Value(value)));
|
|
|
|
},
|
|
|
|
),
|
|
|
|
TextField(
|
|
|
|
decoration: InputDecoration(
|
|
|
|
labelText: 'Sound',
|
|
|
|
),
|
|
|
|
onChanged: (value) {
|
|
|
|
db
|
|
|
|
.update(db.settings)
|
|
|
|
.write(SettingsCompanion(sound: Value(value)));
|
|
|
|
},
|
|
|
|
),
|
|
|
|
TextField(
|
|
|
|
decoration: InputDecoration(
|
|
|
|
labelText: 'Light Color',
|
|
|
|
),
|
|
|
|
onChanged: (value) {
|
|
|
|
db
|
|
|
|
.update(db.settings)
|
|
|
|
.write(SettingsCompanion(lightColor: Value(value)));
|
|
|
|
},
|
|
|
|
),
|
|
|
|
TextField(
|
|
|
|
decoration: InputDecoration(
|
|
|
|
labelText: 'Dark Color',
|
|
|
|
),
|
|
|
|
onChanged: (value) {
|
|
|
|
db
|
|
|
|
.update(db.settings)
|
|
|
|
.write(SettingsCompanion(darkColor: Value(value)));
|
|
|
|
},
|
|
|
|
),
|
|
|
|
TextField(
|
|
|
|
decoration: InputDecoration(
|
|
|
|
labelText: 'Date',
|
|
|
|
),
|
|
|
|
onChanged: (value) {
|
|
|
|
db
|
|
|
|
.update(db.settings)
|
|
|
|
.write(SettingsCompanion(date: Value(value)));
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|