fix: eliminate cross-app consistency drift
This commit is contained in:
@@ -9,11 +9,6 @@ import '../utils/provider_extensions.dart';
|
||||
/// and replacing items in lists, while allowing each screen to customize
|
||||
/// which lists should be updated.
|
||||
mixin ItemUpdatable<T extends StatefulWidget> on State<T> {
|
||||
/// Override to enable backend-aware item refresh. [updateItem] resolves
|
||||
/// the right [MediaServerClient] for the item's server. When null,
|
||||
/// [updateItem] is a no-op.
|
||||
String? get itemServerId => null;
|
||||
|
||||
/// Updates a single item in the screen's list(s) after watch state changes
|
||||
///
|
||||
/// Fetches the latest metadata with images (including clearLogo) and
|
||||
@@ -21,17 +16,18 @@ mixin ItemUpdatable<T extends StatefulWidget> on State<T> {
|
||||
///
|
||||
/// If the fetch fails, the error is silently caught and the item will
|
||||
/// be updated on the next full refresh.
|
||||
Future<void> updateItem(String itemId) async {
|
||||
Future<void> updateItem(MediaItem source) async {
|
||||
if (!mounted) return;
|
||||
|
||||
final serverId = source.serverId;
|
||||
if (serverId == null) return;
|
||||
|
||||
try {
|
||||
final serverId = itemServerId;
|
||||
if (serverId == null) return;
|
||||
final updatedItem = await context.tryGetMediaClientForServer(ServerId(serverId))?.fetchItem(itemId);
|
||||
final updatedItem = await context.tryGetMediaClientForServer(ServerId(serverId))?.fetchItem(source.id);
|
||||
if (updatedItem != null) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
updateItemInLists(itemId, updatedItem);
|
||||
updateItemInLists(source.globalKey, updatedItem);
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -39,20 +35,12 @@ mixin ItemUpdatable<T extends StatefulWidget> on State<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Override this method to specify which list(s) should be updated
|
||||
/// Override this method to specify which list(s) should be updated.
|
||||
///
|
||||
/// This method is called within [setState], so you should directly
|
||||
/// modify your list(s) without calling setState again.
|
||||
/// This method is called within [setState], so implementations should
|
||||
/// directly modify their lists without calling [setState] again.
|
||||
///
|
||||
/// Example:
|
||||
/// ```dart
|
||||
/// @override
|
||||
/// void updateItemInLists(String itemId, MediaItem updatedItem) {
|
||||
/// final index = _items.indexWhere((item) => item.id == itemId);
|
||||
/// if (index != -1) {
|
||||
/// _items[index] = updatedItem;
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
void updateItemInLists(String itemId, MediaItem updatedItem);
|
||||
/// [sourceGlobalKey] is the server-qualified identity of the item that
|
||||
/// initiated the refresh.
|
||||
void updateItemInLists(String sourceGlobalKey, MediaItem updatedItem);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user