feat: add field selection dialog for bulk re-enrich metadata

Add a bottom sheet dialog that lets users choose which metadata field
groups to update during bulk re-enrich (cover, lyrics, album/album
artist, track/disc number, date/ISRC, genre/label/copyright).

Backend (Go):
- Filter FLAC Metadata struct and FFmpeg metadata map by selected
  update_fields so non-selected groups preserve existing file values
- Guard Deezer extended metadata fetch with shouldUpdateField(extra)
- Title/Artist are never overwritten by re-enrich (search keys only)
- enrichedMeta response only includes selected field groups

Frontend (Dart):
- New re_enrich_field_dialog.dart bottom sheet with checkboxes
- FFmpegService embed methods gain preserveMetadata param that uses
  -map_metadata 0 instead of -1 to preserve non-selected tags
- Hide selection overlay/bar before showing dialog, restore on cancel
- Fix setState-after-dispose guard in cancel branches

Cleanup:
- Remove dead code in library_tracks_folder_screen.dart
- Fix use_build_context_synchronously in main_shell.dart
- Suppress false-positive use_null_aware_elements lints
- Update l10n label from 'Title, Artist, Album' to 'Album, Album Artist'
This commit is contained in:
zarzet
2026-03-31 18:21:45 +07:00
parent 7dba938299
commit 3a60ea2f4e
24 changed files with 855 additions and 331 deletions
+206
View File
@@ -0,0 +1,206 @@
import 'package:flutter/material.dart';
import '../l10n/app_localizations.dart';
/// Field group keys matching the Go backend `update_fields` values.
class ReEnrichFields {
static const String cover = 'cover';
static const String lyrics = 'lyrics';
static const String basicTags = 'basic_tags';
static const String trackInfo = 'track_info';
static const String releaseInfo = 'release_info';
static const String extra = 'extra';
static const List<String> all = [
cover,
lyrics,
basicTags,
trackInfo,
releaseInfo,
extra,
];
}
/// Result returned by the re-enrich field selection sheet.
class ReEnrichFieldSelection {
final List<String> fields;
const ReEnrichFieldSelection(this.fields);
/// True when every available field is selected (or update_fields can be omitted).
bool get isAll => fields.length == ReEnrichFields.all.length;
}
/// Shows a bottom sheet that lets the user pick which metadata fields to update
/// during a bulk re-enrich operation.
///
/// Returns `null` when cancelled, or a [ReEnrichFieldSelection] when confirmed.
Future<ReEnrichFieldSelection?> showReEnrichFieldDialog(
BuildContext context, {
required int selectedCount,
}) {
return showModalBottomSheet<ReEnrichFieldSelection>(
context: context,
useRootNavigator: true,
showDragHandle: true,
isScrollControlled: true,
builder: (ctx) => _ReEnrichFieldSheet(selectedCount: selectedCount),
);
}
class _ReEnrichFieldSheet extends StatefulWidget {
final int selectedCount;
const _ReEnrichFieldSheet({required this.selectedCount});
@override
State<_ReEnrichFieldSheet> createState() => _ReEnrichFieldSheetState();
}
class _ReEnrichFieldSheetState extends State<_ReEnrichFieldSheet> {
final Set<String> _selected = Set<String>.from(ReEnrichFields.all);
bool get _allSelected => _selected.length == ReEnrichFields.all.length;
void _toggleAll(bool? value) {
setState(() {
if (value == true) {
_selected.addAll(ReEnrichFields.all);
} else {
_selected.clear();
}
});
}
void _toggle(String field, bool? value) {
setState(() {
if (value == true) {
_selected.add(field);
} else {
_selected.remove(field);
}
});
}
String _labelFor(String field, AppLocalizations l10n) {
switch (field) {
case ReEnrichFields.cover:
return l10n.trackReEnrichFieldCover;
case ReEnrichFields.lyrics:
return l10n.trackReEnrichFieldLyrics;
case ReEnrichFields.basicTags:
return l10n.trackReEnrichFieldBasicTags;
case ReEnrichFields.trackInfo:
return l10n.trackReEnrichFieldTrackInfo;
case ReEnrichFields.releaseInfo:
return l10n.trackReEnrichFieldReleaseInfo;
case ReEnrichFields.extra:
return l10n.trackReEnrichFieldExtra;
default:
return field;
}
}
IconData _iconFor(String field) {
switch (field) {
case ReEnrichFields.cover:
return Icons.image_outlined;
case ReEnrichFields.lyrics:
return Icons.lyrics_outlined;
case ReEnrichFields.basicTags:
return Icons.album_outlined;
case ReEnrichFields.trackInfo:
return Icons.format_list_numbered;
case ReEnrichFields.releaseInfo:
return Icons.calendar_today_outlined;
case ReEnrichFields.extra:
return Icons.label_outline;
default:
return Icons.tag;
}
}
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context);
final colorScheme = Theme.of(context).colorScheme;
final textTheme = Theme.of(context).textTheme;
return SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Title
Padding(
padding: const EdgeInsets.fromLTRB(24, 0, 24, 4),
child: Text(
l10n.trackReEnrich,
style: textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.bold,
),
),
),
// Subtitle
Padding(
padding: const EdgeInsets.fromLTRB(24, 0, 24, 4),
child: Text(
l10n.trackReEnrichOnlineSubtitle,
style: textTheme.bodyMedium?.copyWith(
color: colorScheme.onSurfaceVariant,
),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(24, 0, 24, 8),
child: Text(
l10n.downloadedAlbumSelectedCount(widget.selectedCount),
style: textTheme.bodySmall?.copyWith(
color: colorScheme.onSurfaceVariant,
),
),
),
const Divider(height: 1),
// Select All
CheckboxListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 16),
title: Text(
l10n.trackReEnrichSelectAll,
style: const TextStyle(fontWeight: FontWeight.w600),
),
value: _allSelected,
tristate: true,
onChanged: _toggleAll,
controlAffinity: ListTileControlAffinity.leading,
),
const Divider(height: 1, indent: 16, endIndent: 16),
// Individual fields
for (final field in ReEnrichFields.all)
CheckboxListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 16),
secondary: Icon(_iconFor(field), size: 20),
title: Text(_labelFor(field, l10n)),
value: _selected.contains(field),
onChanged: (v) => _toggle(field, v),
controlAffinity: ListTileControlAffinity.leading,
),
const SizedBox(height: 8),
// Confirm button
Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 16, 16),
child: SizedBox(
width: double.infinity,
child: FilledButton.icon(
onPressed: _selected.isEmpty
? null
: () => Navigator.pop(
context,
ReEnrichFieldSelection(_selected.toList()),
),
icon: const Icon(Icons.auto_fix_high, size: 18),
label: Text(l10n.trackReEnrich),
),
),
),
],
),
);
}
}