Add sound picker
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class DynamicColorScheme extends StatefulWidget {
|
||||
final Color Function(Brightness brightness) data;
|
||||
final Widget Function(BuildContext context, ColorScheme colorScheme) builder;
|
||||
|
||||
const DynamicColorScheme({
|
||||
required this.data,
|
||||
required this.builder,
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
createState() => _DynamicColorSchemeState();
|
||||
}
|
||||
|
||||
class _DynamicColorSchemeState extends State<DynamicColorScheme> {
|
||||
late final ValueNotifier<Brightness> brightness;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
brightness = ValueNotifier(MediaQuery.of(context).platformBrightness);
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
brightness.value = MediaQuery.of(context).platformBrightness;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ValueListenableBuilder<Brightness>(
|
||||
valueListenable: brightness,
|
||||
builder: (context, platformBrightness, child) {
|
||||
final colorScheme = ColorScheme.fromSwatch(
|
||||
brightness: platformBrightness,
|
||||
primarySwatch: Colors.blue,
|
||||
accentColor: Colors.blueAccent,
|
||||
).copyWith(
|
||||
secondary: Colors.red,
|
||||
);
|
||||
final color = widget.data(platformBrightness);
|
||||
return widget.builder(
|
||||
context,
|
||||
colorScheme.copyWith(
|
||||
primary: color,
|
||||
));
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
+9
-41
@@ -2,6 +2,7 @@ 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 {
|
||||
@@ -47,7 +48,6 @@ class _SettingsPageState extends State<_SettingsPage> {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: material.Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -105,46 +105,14 @@ class _SettingsPageState extends State<_SettingsPage> {
|
||||
.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)));
|
||||
},
|
||||
),
|
||||
Center(
|
||||
child: SoundPicker(
|
||||
path: settings.sound,
|
||||
onSelect: (path) {
|
||||
db
|
||||
.update(db.settings)
|
||||
.write(SettingsCompanion(sound: Value(path)));
|
||||
})),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import 'package:audioplayers/audioplayers.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:path/path.dart';
|
||||
|
||||
class SoundPicker extends StatefulWidget {
|
||||
const SoundPicker({super.key, required this.onSelect, required this.path});
|
||||
|
||||
final Function(String path) onSelect;
|
||||
final String? path;
|
||||
|
||||
@override
|
||||
createState() => _SoundPickerState();
|
||||
}
|
||||
|
||||
class _SoundPickerState extends State<SoundPicker> {
|
||||
final audioPlayer = AudioPlayer();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
audioPlayer.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ElevatedButton(
|
||||
onPressed: () async {
|
||||
FilePickerResult? result = await FilePicker.platform.pickFiles(
|
||||
type: FileType.audio,
|
||||
);
|
||||
if (result == null) return;
|
||||
final path = result.files.first.path;
|
||||
if (path == null) return;
|
||||
await audioPlayer.play(DeviceFileSource(path));
|
||||
widget.onSelect(path);
|
||||
},
|
||||
child: Text(widget.path != null
|
||||
? "Sound: ${basename(widget.path!)}"
|
||||
: 'Alarm sound'),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user