simplify _buildAssetRow

shenlong-tanwen 2025-11-12 22:57:14 +05:30
parent 02de19df6d
commit bd8ef9e1bf
1 changed files with 37 additions and 48 deletions

View File

@ -142,12 +142,7 @@ class _FixedSegmentRow extends ConsumerWidget {
TimelineService timelineService,
bool isDynamicLayout,
) {
if (!isDynamicLayout) {
return TimelineRow.fixed(
dimension: tileHeight,
spacing: spacing,
textDirection: Directionality.of(context),
children: [
final children = [
for (int i = 0; i < assets.length; i++)
TimelineAssetIndexWrapper(
assetIndex: assetIndex + i,
@ -158,10 +153,11 @@ class _FixedSegmentRow extends ConsumerWidget {
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 meanAspectRatio = aspectRatios.sum / assets.length;
@ -177,8 +173,12 @@ class _FixedSegmentRow extends ConsumerWidget {
// Normalize to get width distribution
final sum = arConfiguration.sum;
int index = 0;
for (final ratio in arConfiguration) {
// 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(
child: TimelineRow(
@ -186,18 +186,7 @@ class _FixedSegmentRow extends ConsumerWidget {
widths: widths,
spacing: spacing,
textDirection: Directionality.of(context),
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,
),
),
],
children: children,
),
);
}