From a2e5652d1951a7580a1b95c96d718206a3c5a4ab Mon Sep 17 00:00:00 2001 From: mertalev <101130780+mertalev@users.noreply.github.com> Date: Wed, 30 Jul 2025 20:55:48 -0400 Subject: [PATCH] preserve subtree --- .../widgets/timeline/fixed/segment.model.dart | 38 +++++++------------ 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/mobile/lib/presentation/widgets/timeline/fixed/segment.model.dart b/mobile/lib/presentation/widgets/timeline/fixed/segment.model.dart index fdb5ddf692..78c0744749 100644 --- a/mobile/lib/presentation/widgets/timeline/fixed/segment.model.dart +++ b/mobile/lib/presentation/widgets/timeline/fixed/segment.model.dart @@ -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>( - future: null, - initialData: assets, - builder: (context, snapshot) { - return _buildAssetRow(context, snapshot.data, timelineService); - }, - ); + return _buildAssetRow(context, assets, timelineService); } catch (e) { return FutureBuilder>( future: timelineService.loadAssets(assetIndex, assetCount), @@ -137,22 +126,21 @@ class _FixedSegmentRow extends ConsumerWidget { } Widget _buildAssetRow(BuildContext context, List? 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), + ); + }), ); } } @@ -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);