simplify _buildAssetRow

This commit is contained in:
shenlong-tanwen
2025-11-12 22:57:14 +05:30
parent 01e7f6a01c
commit 33a114f407

View File

@@ -142,12 +142,7 @@ class _FixedSegmentRow extends ConsumerWidget {
TimelineService timelineService, TimelineService timelineService,
bool isDynamicLayout, bool isDynamicLayout,
) { ) {
if (!isDynamicLayout) { final children = [
return TimelineRow.fixed(
dimension: tileHeight,
spacing: spacing,
textDirection: Directionality.of(context),
children: [
for (int i = 0; i < assets.length; i++) for (int i = 0; i < assets.length; i++)
TimelineAssetIndexWrapper( TimelineAssetIndexWrapper(
assetIndex: assetIndex + i, assetIndex: assetIndex + i,
@@ -158,10 +153,11 @@ class _FixedSegmentRow extends ConsumerWidget {
assetIndex: assetIndex + i, assetIndex: assetIndex + i,
), ),
), ),
], ];
);
}
final widths = List.filled(assets.length, tileHeight);
if (isDynamicLayout) {
final aspectRatios = assets.map((e) => (e.width ?? 1) / (e.height ?? 1)).toList(); final aspectRatios = assets.map((e) => (e.width ?? 1) / (e.height ?? 1)).toList();
final meanAspectRatio = aspectRatios.sum / assets.length; final meanAspectRatio = aspectRatios.sum / assets.length;
@@ -177,8 +173,12 @@ class _FixedSegmentRow extends ConsumerWidget {
// Normalize to get width distribution // Normalize to get width distribution
final sum = arConfiguration.sum; final sum = arConfiguration.sum;
int index = 0;
for (final ratio in arConfiguration) {
// Distribute the available width proportionally based on aspect ratio configuration // Distribute the available width proportionally based on aspect ratio configuration
final widths = arConfiguration.map((e) => ((e * assets.length) / sum) * tileHeight).toList(); widths[index++] = ((ratio * assets.length) / sum) * tileHeight;
}
}
return TimelineDragRegion( return TimelineDragRegion(
child: TimelineRow( child: TimelineRow(
@@ -186,18 +186,7 @@ class _FixedSegmentRow extends ConsumerWidget {
widths: widths, widths: widths,
spacing: spacing, spacing: spacing,
textDirection: Directionality.of(context), textDirection: Directionality.of(context),
children: [ children: children,
for (int i = 0; i < assets.length; i++)
TimelineAssetIndexWrapper(
assetIndex: assetIndex + i,
segmentIndex: 0, // For simplicity, using 0 for now
child: _AssetTileWidget(
key: ValueKey(Object.hash(assets[i].heroTag, assetIndex + i, timelineService.hashCode)),
asset: assets[i],
assetIndex: assetIndex + i,
),
),
],
), ),
); );
} }