Files
SpotiFLAC-Mobile/lib/widgets/playback_source_label.dart
T
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

70 lines
2.1 KiB
Dart

import 'package:audio_service/audio_service.dart' show MediaItem;
import 'package:material_ui/material_ui.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:mornye/l10n/l10n.dart';
import 'package:mornye/services/link/link_source_names.dart';
import 'package:mornye/services/network_storage_service.dart';
final _sourceNameProvider = FutureProvider.family<String?, String>((
ref,
id,
) async {
try {
return (await NetworkStorageService.instance.connection(id)).name;
} catch (_) {
return null;
}
});
/// Describes the file actually opened, including an offline copy preferred
/// over a network source already in the queue.
class PlaybackSourceLabel extends ConsumerWidget {
const PlaybackSourceLabel({
super.key,
required this.item,
this.color,
this.style,
this.padding = const EdgeInsets.only(top: 4),
});
final MediaItem item;
final Color? color;
/// The text style, drawn in [color]; `labelSmall` by default.
final TextStyle? style;
final EdgeInsetsGeometry padding;
@override
Widget build(BuildContext context, WidgetRef ref) {
final source = item.extras?['source']?.toString() ?? '';
final origin = item.extras?['originSource']?.toString();
final network = source.startsWith('network://') ? source : origin;
if (network == null) return const SizedBox.shrink();
final resolved = item.extras?['resolvedSource']?.toString() ?? source;
final local = !const {
'network',
'http',
'https',
}.contains(Uri.tryParse(resolved)?.scheme);
var label = context.l10n.offlinePlayingLocal;
if (!local) {
final host = Uri.tryParse(network)?.host ?? '';
final name =
ref.watch(linkSourceNamesProvider)[host] ??
ref.watch(_sourceNameProvider(host)).value ??
host;
label = context.l10n.offlineStreaming(name);
}
return Padding(
padding: padding,
child: Text(
label,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: (style ?? Theme.of(context).textTheme.labelSmall)?.copyWith(
color: color,
),
),
);
}
}