Files
Melo/lib/player/now_playing_screen.dart
T
Hermes (Server)andClaude Opus 5 bc861f6087 UI-Politur: Kontrast, Abstaende, Typografie, Bewegung
Kein Redesign — Schwarz/Rot, 4 Tabs und Lieder/Kategorie bleiben. Grundlage
sind die Design-Skills: ui-ux-pro-max (Barrierefreiheit, Touch, Typografie,
Bewegung), ui-design/mobile-android (Material 3) und die Token-Disziplin
aus Hue.

Behobene Maengel (messbar, nicht Geschmack):
- Text in Colors.white38 an 17 Stellen = 3,4:1 Kontrast, WCAG verlangt
  4,5:1. Ersetzt durch drei benannte Stufen (text1 15,9:1 / text2 8,8:1 /
  text3 4,9:1). theme_kontrast_test.dart rechnet die Verhaeltnisse bei
  jedem Lauf nach, statt sie zu behaupten.
- SubTabs waren ~38 dp hoch (Material 3 verlangt 48), ohne Ripple und ohne
  Uebergang. Jetzt 48 dp, InkWell, AnimatedContainer, und die Auswahl wird
  Vorlesehilfen als Zustand gemeldet (Semantics.selected).
- mini_player.dart: Expanded UM eine feste Hoehe herum — zwei
  widerspruechliche Angaben. Entschaerft.
- Emoji in Bedienelementen der Einstellungen (jeweils neben einem echten
  Icon) entfernt.

Neu in shared/theme.dart: MeloSpace (8er-Raster), MeloRadius, MeloMotion,
Farbrollen text1/2/3 + border + hairline, minTouchTarget, vollstaendiges
textTheme (7 Stufen) und Themes fuer Listen, Sheets, Snackbars,
Fortschritt, Trenner.

318 Tests gruen (23 neue, 1 uebersprungen), flutter analyze ohne Befund.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FpPu4nuKjKKeX1RpdDeX81
2026-08-21 12:40:25 +02:00

398 lines
13 KiB
Dart

import 'package:audio_service/audio_service.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../library/database.dart';
import '../services/navidrome_service.dart';
import '../shared/cover.dart';
import '../shared/favorite_button.dart';
import '../shared/theme.dart';
import 'audio_handler.dart';
import 'queue_screen.dart';
/// Vollbild-Wiedergabe: Cover, Titel, Fortschritt, Transport-Controls.
class NowPlayingScreen extends StatelessWidget {
const NowPlayingScreen({super.key});
void _showLyrics(BuildContext context, String songId) {
showModalBottomSheet(
context: context,
builder: (ctx) => _LyricsSheet(songId: songId),
);
}
@override
Widget build(BuildContext context) {
final handler = context.read<MeloAudioHandler>();
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.transparent,
actions: [
StreamBuilder<MediaItem?>(
stream: handler.mediaItem,
builder: (context, snapshot) {
final item = snapshot.data;
if (item == null) return const SizedBox.shrink();
return Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
tooltip: 'Songtext',
icon: const Icon(Icons.lyrics),
onPressed: () => _showLyrics(
context, item.extras?['songId'] as String? ?? item.id),
),
FavoriteButton(songId: item.extras?['songId'] as String? ?? ''),
],
);
},
),
_SleepTimerButton(handler: handler),
IconButton(
tooltip: 'Warteschlange',
icon: const Icon(Icons.queue_music),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(builder: (_) => const QueueScreen()),
),
),
],
),
body: SafeArea(
child: StreamBuilder<MediaItem?>(
stream: handler.mediaItem,
builder: (context, snapshot) {
final item = snapshot.data;
if (item == null) {
return const Center(child: Text('Nichts in Wiedergabe'));
}
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 24),
child: Column(
children: [
Expanded(child: Center(child: _Cover(item: item))),
const SizedBox(height: 24),
Text(
item.title,
style: Theme.of(context).textTheme.headlineSmall,
maxLines: 2,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
),
const SizedBox(height: 8),
Text(
item.artist ?? 'Unbekannt',
style: const TextStyle(color: MeloTheme.text2),
),
const SizedBox(height: 24),
_ProgressBar(handler: handler),
const _Controls(),
const SizedBox(height: 16),
],
),
);
},
),
),
);
}
}
class _Cover extends StatelessWidget {
const _Cover({required this.item});
final MediaItem item;
@override
Widget build(BuildContext context) {
return AspectRatio(
aspectRatio: 1,
child: CoverImage(artUri: item.artUri, radius: 16),
);
}
}
class _ProgressBar extends StatelessWidget {
const _ProgressBar({required this.handler});
final MeloAudioHandler handler;
@override
Widget build(BuildContext context) {
return StreamBuilder<Duration?>(
stream: handler.durationStream,
builder: (context, dSnap) {
final total = dSnap.data ?? Duration.zero;
return StreamBuilder<Duration>(
stream: handler.positionStream,
builder: (context, pSnap) {
var position = pSnap.data ?? Duration.zero;
final hasDuration = total > Duration.zero;
if (hasDuration && position > total) position = total;
final maxMs = hasDuration ? total.inMilliseconds.toDouble() : 1.0;
final valueMs =
position.inMilliseconds.toDouble().clamp(0.0, maxMs).toDouble();
return Column(
children: [
Slider(
value: valueMs,
max: maxMs,
semanticFormatterCallback: (v) =>
_fmt(Duration(milliseconds: v.round())),
onChanged: hasDuration
? (v) => handler.seek(Duration(milliseconds: v.round()))
: null,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(_fmt(position),
style: const TextStyle(color: MeloTheme.text2)),
Text(_fmt(total),
style: const TextStyle(color: MeloTheme.text2)),
],
),
),
],
);
},
);
},
);
}
static String _fmt(Duration d) {
final m = d.inMinutes.remainder(60).toString().padLeft(2, '0');
final s = d.inSeconds.remainder(60).toString().padLeft(2, '0');
return '$m:$s';
}
}
class _Controls extends StatelessWidget {
const _Controls();
@override
Widget build(BuildContext context) {
final handler = context.read<MeloAudioHandler>();
return StreamBuilder<PlaybackState>(
stream: handler.playbackState,
builder: (context, snapshot) {
final state = snapshot.data;
final playing = state?.playing ?? false;
final shuffle = state?.shuffleMode == AudioServiceShuffleMode.all;
final repeat = state?.repeatMode ?? AudioServiceRepeatMode.none;
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
IconButton(
tooltip: 'Zufallswiedergabe',
icon: Icon(Icons.shuffle,
color: shuffle ? MeloTheme.red : MeloTheme.text2),
onPressed: () => handler.setShuffleMode(shuffle
? AudioServiceShuffleMode.none
: AudioServiceShuffleMode.all),
),
IconButton(
tooltip: 'Vorheriger Titel',
iconSize: 40,
icon: const Icon(Icons.skip_previous),
onPressed: handler.skipToPrevious,
),
IconButton(
tooltip: playing ? 'Pause' : 'Abspielen',
iconSize: 64,
icon: Icon(playing ? Icons.pause_circle : Icons.play_circle,
color: MeloTheme.red),
onPressed: playing ? handler.pause : handler.play,
),
IconButton(
tooltip: 'Nächster Titel',
iconSize: 40,
icon: const Icon(Icons.skip_next),
onPressed: handler.skipToNext,
),
IconButton(
tooltip: 'Wiederholen',
icon: Icon(
repeat == AudioServiceRepeatMode.one
? Icons.repeat_one
: Icons.repeat,
color: repeat == AudioServiceRepeatMode.none
? MeloTheme.text2
: MeloTheme.red,
),
onPressed: () => handler.setRepeatMode(switch (repeat) {
AudioServiceRepeatMode.none => AudioServiceRepeatMode.all,
AudioServiceRepeatMode.all => AudioServiceRepeatMode.one,
_ => AudioServiceRepeatMode.none,
}),
),
],
);
},
);
}
}
class _SleepTimerButton extends StatelessWidget {
const _SleepTimerButton({required this.handler});
final MeloAudioHandler handler;
void _showSleepOptions(BuildContext context) {
showModalBottomSheet(
context: context,
builder: (ctx) => Container(
color: Theme.of(ctx).scaffoldBackgroundColor,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.all(16),
child: Text(
'Sleep-Timer',
style: Theme.of(ctx).textTheme.titleLarge,
),
),
...const [5, 10, 15, 30, 60].map(
(minutes) => ListTile(
title: Text('$minutes Minuten'),
onTap: () {
handler.sleepTimer.start(Duration(minutes: minutes));
Navigator.pop(ctx);
},
),
),
ValueListenableBuilder<Duration?>(
valueListenable: handler.sleepTimer.remaining,
builder: (_, remaining, _) => remaining == null
? const SizedBox.shrink()
: ListTile(
title: const Text('Timer beenden'),
leading: const Icon(Icons.close),
onTap: () {
handler.sleepTimer.cancel();
Navigator.pop(ctx);
},
),
),
const SizedBox(height: 16),
],
),
),
);
}
@override
Widget build(BuildContext context) {
return ValueListenableBuilder<Duration?>(
valueListenable: handler.sleepTimer.remaining,
builder: (context, remaining, _) {
if (remaining == null) {
return IconButton(
tooltip: 'Sleep-Timer',
icon: const Icon(Icons.bedtime_outlined),
onPressed: () => _showSleepOptions(context),
);
}
final minutes = remaining.inMinutes;
final seconds = (remaining.inSeconds % 60).toString().padLeft(2, '0');
return IconButton(
tooltip: 'Sleep-Timer: noch $minutes:$seconds',
icon: Icon(Icons.bedtime, color: MeloTheme.red),
onPressed: () => _showSleepOptions(context),
);
},
);
}
}
class _LyricsSheet extends StatefulWidget {
const _LyricsSheet({required this.songId});
final String songId;
@override
State<_LyricsSheet> createState() => _LyricsSheetState();
}
class _LyricsSheetState extends State<_LyricsSheet> {
late final NavidromeService _nav = NavidromeService();
String? _text;
bool _loading = true;
@override
void initState() {
super.initState();
_load();
}
/// Zuerst der Songtext aus dem Tag der Datei — der ist sofort da und
/// funktioniert offline. Nur wenn keiner drinsteht, wird der Server gefragt.
Future<void> _load() async {
final db = context.read<MeloDb>();
final lokal = await db.lyricsOf(widget.songId);
if (lokal != null) {
if (mounted) setState(() { _text = lokal; _loading = false; });
return;
}
await _nav.ladeGespeicherteZugangsdaten();
if (_nav.istVerbunden) {
final lyrics = await _nav.getLyrics(widget.songId);
if (mounted) {
setState(() {
_text = lyrics.isEmpty ? null : lyrics.text;
_loading = false;
});
}
return;
}
if (mounted) setState(() => _loading = false);
}
@override
Widget build(BuildContext context) {
return Container(
color: MeloTheme.black,
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(16),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text('📝 Songtext',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600)),
IconButton(
icon: const Icon(Icons.close),
onPressed: () => Navigator.pop(context),
),
],
),
),
Expanded(
child: _loading
? const Center(
child: CircularProgressIndicator(color: MeloTheme.red),
)
: _text == null
? const Center(
child: Text('Kein Songtext verfügbar',
style: TextStyle(color: MeloTheme.text2)),
)
: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Text(
_text!,
style: const TextStyle(
fontSize: 14,
height: 1.6,
color: Colors.white,
),
),
),
),
],
),
);
}
}