Files
SpotiFLAC-Mobile/lib/widgets/playback_normalization_settings.dart
T
zarzet 3d0d198ebd feat(material): size desktop dialogs and show slider values in pills
Desktop sheet dialogs had one 560dp width for every task, so a crash
report or the metadata editor wrapped tightly while short prompts
floated in empty space. AppSheetDialog now takes a size class (compact
440dp, medium 560dp by default, wide 720dp), threaded through the sheet
helpers. The metadata editor, crash report and re-enrich review open
wide. On Material the dialog corner comes from the sheet radius token,
the body's scrollbar stays visible, and a titled header ends with a
close button. Material alert dialogs stay within the M3 280 to 560dp
range, starting at the compact width on desktop.

Settings sliders showed their value inline or not at all. A shared
SliderValueHeader puts the value with its unit in a secondaryContainer
pill at the end of the title row, used by music haptics, normalization
pre-amp, AutoMix, lyrics size and the equalizer tone sliders. These
already save on release; lyrics size and the equalizer keep live writes
because their preview needs every step. Mornye keeps its inline labels.

The player details sheet called showModalBottomSheet with Flutter's
drag handle on Material phones. It now opens through
showAppScrollableBottomSheet with the shared handle, shape and header
naming the track, and lists the tags in one group instead of a titled,
outlined card. Mornye keeps its glass details on both platforms.
2026-10-21 22:13:12 +07:00

108 lines
3.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:mornye/l10n/l10n.dart';
import 'package:mornye/providers/settings_provider.dart';
import 'package:mornye/theme/mornye_theme.dart';
import 'package:mornye/widgets/app_choice_chip.dart';
import 'package:mornye/widgets/app_slider.dart';
import 'package:mornye/widgets/slider_value_header.dart';
/// Gain mode and pre-amp shown under the volume normalization switch.
class PlaybackNormalizationSettings extends ConsumerStatefulWidget {
const PlaybackNormalizationSettings({super.key, required this.enabled});
final bool enabled;
@override
ConsumerState<PlaybackNormalizationSettings> createState() =>
_PlaybackNormalizationSettingsState();
}
class _PlaybackNormalizationSettingsState
extends ConsumerState<PlaybackNormalizationSettings> {
/// ReplayGain 2.0 reference loudness the gain tags are written against.
static const _referenceLufs = -18;
double? _preamp;
static String _signed(int value) => value > 0 ? '+$value' : '$value';
@override
Widget build(BuildContext context) {
final mode = ref.watch(
settingsProvider.select((s) => s.playbackNormalizationMode),
);
final savedPreamp = ref.watch(
settingsProvider.select((s) => s.playbackNormalizationPreamp),
);
final notifier = ref.read(settingsProvider.notifier);
final l10n = context.l10n;
final preamp = (_preamp ?? savedPreamp).round();
final value = l10n.playbackNormalizationPreampValue(
_signed(preamp),
'${_referenceLufs + preamp}',
);
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(l10n.playbackNormalizationMode),
const SizedBox(height: 8),
Wrap(
spacing: 8,
children: [
for (final (id, label) in [
('track', l10n.playbackNormalizationModeTrack),
('album', l10n.playbackNormalizationModeAlbum),
])
AppChoiceChip(
label: Text(label),
selected: mode == id,
singleChoice: true,
onSelected: widget.enabled
? (_) => notifier.setPlaybackNormalizationMode(id)
: null,
),
],
),
const SizedBox(height: 16),
if (context.isMornye)
Text('${l10n.playbackNormalizationPreamp}: $value')
else
SliderValueHeader(
title: l10n.playbackNormalizationPreamp,
value: value,
enabled: widget.enabled,
),
AppSlider(
value: preamp.toDouble(),
min: -15,
max: 6,
divisions: 21,
label: '${_signed(preamp)} dB',
semanticLabel: l10n.playbackNormalizationPreamp,
onChanged: widget.enabled
? (value) => setState(() => _preamp = value)
: null,
onChangeEnd: widget.enabled
? (value) {
notifier.setPlaybackNormalizationPreamp(value);
setState(() => _preamp = null);
}
: null,
),
Text(
l10n.playbackNormalizationPreampHint,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
],
),
);
}
}