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/sound_picker.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 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( 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( 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))); }, ), Center( child: SoundPicker( path: settings.sound, onSelect: (path) { db .update(db.settings) .write(SettingsCompanion(sound: Value(path))); })), ], ), ); }), ); } }