preserve subtree

This commit is contained in:
mertalev 2025-07-30 20:55:48 -04:00
parent ac35678008
commit a2e5652d19
No known key found for this signature in database
GPG Key ID: DF6ABC77AAD98C95

View File

@ -112,20 +112,9 @@ class _FixedSegmentRow extends ConsumerWidget {
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
final timelineService = ref.read(timelineServiceProvider); final timelineService = ref.read(timelineServiceProvider);
if (timelineService.hasRange(assetIndex, assetCount)) {
return _buildAssetRow(context, timelineService.getAssets(assetIndex, assetCount), timelineService);
}
try { try {
final assets = timelineService.getAssets(assetIndex, assetCount); final assets = timelineService.getAssets(assetIndex, assetCount);
return FutureBuilder<List<BaseAsset>>( return _buildAssetRow(context, assets, timelineService);
future: null,
initialData: assets,
builder: (context, snapshot) {
return _buildAssetRow(context, snapshot.data, timelineService);
},
);
} catch (e) { } catch (e) {
return FutureBuilder<List<BaseAsset>>( return FutureBuilder<List<BaseAsset>>(
future: timelineService.loadAssets(assetIndex, assetCount), future: timelineService.loadAssets(assetIndex, assetCount),
@ -137,22 +126,21 @@ class _FixedSegmentRow extends ConsumerWidget {
} }
Widget _buildAssetRow(BuildContext context, List<BaseAsset>? assets, TimelineService timelineService) { Widget _buildAssetRow(BuildContext context, List<BaseAsset>? assets, TimelineService timelineService) {
final assetIndex = this.assetIndex;
return FixedTimelineRow( return FixedTimelineRow(
dimension: tileHeight, dimension: tileHeight,
spacing: spacing, spacing: spacing,
textDirection: Directionality.of(context), textDirection: Directionality.of(context),
children: [ children: List.generate(assetCount, (i) {
for (int i = 0; i < assetCount; i++) final curAssetIndex = assetIndex + i;
TimelineAssetIndexWrapper( return TimelineAssetIndexWrapper(
assetIndex: assetIndex + i, // this key is intentionally generic to preserve the state of the widget and its subtree
segmentIndex: 0, // For simplicity, using 0 for now key: ValueKey(i.hashCode ^ timelineService.hashCode),
child: _AssetTileWidget( assetIndex: curAssetIndex,
key: ValueKey(i.hashCode ^ (assetIndex + i).hashCode ^ timelineService.hashCode), segmentIndex: 0, // For simplicity, using 0 for now
asset: assets == null ? null : assets[i], child: _AssetTileWidget(asset: assets?[i], assetIndex: curAssetIndex),
assetIndex: assetIndex + i, );
), }),
),
],
); );
} }
} }
@ -161,7 +149,7 @@ class _AssetTileWidget extends ConsumerWidget {
final BaseAsset? asset; final BaseAsset? asset;
final int assetIndex; 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 { Future _handleOnTap(BuildContext ctx, WidgetRef ref, int assetIndex, BaseAsset asset, int? heroOffset) async {
final multiSelectState = ref.read(multiSelectProvider); final multiSelectState = ref.read(multiSelectProvider);