Files
SpotiFLAC-Mobile/lib/widgets/playback_normalization_settings.dart
zarzet 962e582acc chore(flutter): move to Flutter 3.50.0 and the material_ui packages
Flutter 3.50 deprecates its built-in Material and Cupertino libraries in
favour of the material_ui and cupertino_ui packages. The imports move
with the official fix (dart fix, migrate_design_widgets); the app's old
two-library theme bridge collapses into one Theme type.

- MaterialExpressiveScope keeps the complete host theme nearest its
  child. The reduced copy made for the expressive widgets now shares the
  app's Theme type and would hide component themes and extensions.
- LegacyThemeBrightness hands the brightness to the glass package, which
  still reads Flutter's built-in theme.
- appLocalizationsDelegates lists the material_ui localization delegates;
  the generated list still names the built-in ones.
- Tests: findByTooltip and pageBack replace the flutter_test helpers that
  only know the built-in widgets, and several tests that had gone stale
  against earlier app changes are repaired.
2026-11-15 23:33:29 +07:00

108 lines
3.6 KiB
Dart

import 'package:material_ui/material_ui.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,
),
),
],
),
);
}
}