preserve subtree

not growable

minor cleanup
This commit is contained in:
mertalev
2025-07-30 20:55:48 -04:00
parent 4f19dacecd
commit be0fe36210
11 changed files with 40 additions and 65 deletions
@@ -37,7 +37,7 @@ ImageProvider getThumbnailImageProvider({BaseAsset? asset, String? remoteId, Siz
if (_shouldUseLocalAsset(asset!)) {
final id = asset is LocalAsset ? asset.id : (asset as RemoteAsset).localId!;
return LocalThumbProvider(id: id, updatedAt: asset.updatedAt, size: size);
return LocalThumbProvider(id: id, size: size);
}
final String assetId;
@@ -10,9 +10,8 @@ class LocalThumbProvider extends ImageProvider<LocalThumbProvider> {
final String id;
final Size size;
final DateTime? updatedAt;
const LocalThumbProvider({required this.id, required this.size, this.updatedAt});
const LocalThumbProvider({required this.id, required this.size});
@override
Future<LocalThumbProvider> obtainKey(ImageConfiguration configuration) {
@@ -25,7 +24,6 @@ class LocalThumbProvider extends ImageProvider<LocalThumbProvider> {
_codec(key),
informationCollector: () => <DiagnosticsNode>[
DiagnosticsProperty<String>('Id', key.id),
DiagnosticsProperty<DateTime>('Updated at', key.updatedAt),
DiagnosticsProperty<Size>('Size', key.size),
],
);
@@ -40,13 +38,13 @@ class LocalThumbProvider extends ImageProvider<LocalThumbProvider> {
bool operator ==(Object other) {
if (identical(this, other)) return true;
if (other is LocalThumbProvider) {
return id == other.id && size == other.size && updatedAt == other.updatedAt;
return id == other.id && size == other.size;
}
return false;
}
@override
int get hashCode => id.hashCode ^ updatedAt.hashCode;
int get hashCode => id.hashCode ^ size.hashCode;
}
class LocalFullImageProvider extends ImageProvider<LocalFullImageProvider> {
@@ -112,20 +112,9 @@ class _FixedSegmentRow extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final timelineService = ref.read(timelineServiceProvider);
if (timelineService.hasRange(assetIndex, assetCount)) {
return _buildAssetRow(context, timelineService.getAssets(assetIndex, assetCount), timelineService);
}
try {
final assets = timelineService.getAssets(assetIndex, assetCount);
return FutureBuilder<List<BaseAsset>>(
future: null,
initialData: assets,
builder: (context, snapshot) {
return _buildAssetRow(context, snapshot.data, timelineService);
},
);
return _buildAssetRow(context, assets, timelineService);
} catch (e) {
return FutureBuilder<List<BaseAsset>>(
future: timelineService.loadAssets(assetIndex, assetCount),
@@ -137,22 +126,21 @@ class _FixedSegmentRow extends ConsumerWidget {
}
Widget _buildAssetRow(BuildContext context, List<BaseAsset>? assets, TimelineService timelineService) {
final assetIndex = this.assetIndex;
return FixedTimelineRow(
dimension: tileHeight,
spacing: spacing,
textDirection: Directionality.of(context),
children: [
for (int i = 0; i < assetCount; i++)
TimelineAssetIndexWrapper(
assetIndex: assetIndex + i,
segmentIndex: 0, // For simplicity, using 0 for now
child: _AssetTileWidget(
key: ValueKey(i.hashCode ^ (assetIndex + i).hashCode ^ timelineService.hashCode),
asset: assets == null ? null : assets[i],
assetIndex: assetIndex + i,
),
),
],
children: List.generate(assetCount, (i) {
final curAssetIndex = assetIndex + i;
return TimelineAssetIndexWrapper(
// this key is intentionally generic to preserve the state of the widget and its subtree
key: ValueKey(i.hashCode ^ timelineService.hashCode),
assetIndex: curAssetIndex,
segmentIndex: 0, // For simplicity, using 0 for now
child: _AssetTileWidget(asset: assets?[i], assetIndex: curAssetIndex),
);
}, growable: false),
);
}
}
@@ -161,7 +149,7 @@ class _AssetTileWidget extends ConsumerWidget {
final BaseAsset? asset;
final int assetIndex;
const _AssetTileWidget({super.key, required this.asset, required this.assetIndex});
const _AssetTileWidget({required this.asset, required this.assetIndex});
Future _handleOnTap(BuildContext ctx, WidgetRef ref, int assetIndex, BaseAsset asset, int? heroOffset) async {
final multiSelectState = ref.read(multiSelectProvider);
@@ -101,7 +101,6 @@ class _SliverTimeline extends ConsumerStatefulWidget {
class _SliverTimelineState extends ConsumerState<_SliverTimeline> {
final _scrollController = ScrollController();
StreamSubscription? _eventSubscription;
// late final KeepAliveLink asyncSegmentsLink;
// Drag selection state
bool _dragging = false;