39 lines
1.5 KiB
Dart
39 lines
1.5 KiB
Dart
import 'package:flutter/widgets.dart';
|
|
import '../media/ids.dart';
|
|
|
|
import '../media/media_item.dart';
|
|
import '../media/media_server_client.dart';
|
|
import '../services/plex_client.dart';
|
|
import '../utils/global_key_utils.dart';
|
|
import '../utils/provider_extensions.dart';
|
|
|
|
/// Shared helpers for screens bound to a single [MediaItem]/server.
|
|
mixin ServerBoundMediaMixin<T extends StatefulWidget> on State<T> {
|
|
MediaItem get serverBoundMetadata;
|
|
|
|
bool get isServerBoundOffline => false;
|
|
|
|
String? get serverBoundServerId => serverBoundMetadata.serverId;
|
|
|
|
String toServerBoundGlobalKey(String ratingKey, {ServerId? serverId}) {
|
|
final resolved = serverId ?? serverIdOrNull(serverBoundServerId);
|
|
if (resolved == null) {
|
|
throw StateError('Cannot build server-bound key without a serverId');
|
|
}
|
|
return buildGlobalKey(resolved, ratingKey);
|
|
}
|
|
|
|
/// Returns the [PlexClient] for the bound server, or null when offline /
|
|
/// the server is Jellyfin / not registered. Use [getServerBoundMediaClient]
|
|
/// for backend-neutral flows.
|
|
PlexClient? getServerBoundPlexClient(BuildContext context) {
|
|
if (isServerBoundOffline) return null;
|
|
return context.tryGetPlexClientForServer(serverIdOrNull(serverBoundMetadata.serverId));
|
|
}
|
|
|
|
/// Returns a backend-neutral [MediaServerClient] for the bound server, or
|
|
/// null when offline / not registered.
|
|
MediaServerClient? getServerBoundMediaClient(BuildContext context) =>
|
|
context.getMediaClientForItemOrNull(serverBoundMetadata, isOffline: isServerBoundOffline);
|
|
}
|