106 lines
3.0 KiB
Dart
106 lines
3.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../models/song.dart';
|
|
import '../database/db_helper.dart';
|
|
import '../utils/farb_theme.dart';
|
|
|
|
class MetadatenDialog extends StatefulWidget {
|
|
final Song song;
|
|
const MetadatenDialog({super.key, required this.song});
|
|
|
|
@override
|
|
State<MetadatenDialog> createState() => _MetadatenDialogState();
|
|
}
|
|
|
|
class _MetadatenDialogState extends State<MetadatenDialog> {
|
|
late TextEditingController _titelCtrl;
|
|
late TextEditingController _kuenstlerCtrl;
|
|
late TextEditingController _albumCtrl;
|
|
final DbHelper _db = DbHelper();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_titelCtrl = TextEditingController(text: widget.song.titel);
|
|
_kuenstlerCtrl = TextEditingController(text: widget.song.kuenstler);
|
|
_albumCtrl = TextEditingController(text: widget.song.album);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_titelCtrl.dispose();
|
|
_kuenstlerCtrl.dispose();
|
|
_albumCtrl.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AlertDialog(
|
|
backgroundColor: MeloTheme.dunkel1,
|
|
title: const Text('✏️ Metadaten', style: TextStyle(color: Colors.white, fontSize: 18)),
|
|
content: SingleChildScrollView(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
_field('Titel', _titelCtrl),
|
|
const SizedBox(height: 12),
|
|
_field('Künstler', _kuenstlerCtrl),
|
|
const SizedBox(height: 12),
|
|
_field('Album', _albumCtrl),
|
|
],
|
|
),
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context, false),
|
|
child: const Text('Abbrechen', style: TextStyle(color: Colors.white54)),
|
|
),
|
|
TextButton(
|
|
onPressed: () => _speichern(),
|
|
child: const Text('Speichern', style: TextStyle(color: MeloTheme.rot)),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _field(String label, TextEditingController ctrl) {
|
|
return TextField(
|
|
controller: ctrl,
|
|
style: const TextStyle(color: Colors.white),
|
|
decoration: InputDecoration(
|
|
labelText: label,
|
|
labelStyle: const TextStyle(color: Colors.grey),
|
|
border: const OutlineInputBorder(),
|
|
focusedBorder: const OutlineInputBorder(
|
|
borderSide: BorderSide(color: MeloTheme.rot),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> _speichern() async {
|
|
final id = widget.song.id;
|
|
if (id == null) {
|
|
if (mounted) Navigator.pop(context, false);
|
|
return;
|
|
}
|
|
final titel = _titelCtrl.text.trim();
|
|
final kuenstler = _kuenstlerCtrl.text.trim();
|
|
final album = _albumCtrl.text.trim();
|
|
if (titel.isEmpty) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text('Titel darf nicht leer sein')),
|
|
);
|
|
return;
|
|
}
|
|
|
|
await _db.metadatenAktualisieren(
|
|
id,
|
|
titel: titel,
|
|
kuenstler: kuenstler,
|
|
album: album,
|
|
);
|
|
if (mounted) Navigator.pop(context, true);
|
|
}
|
|
}
|