simplify _buildAssetRow

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

View File

@@ -142,62 +142,51 @@ class _FixedSegmentRow extends ConsumerWidget {
TimelineService timelineService, TimelineService timelineService,
bool isDynamicLayout, bool isDynamicLayout,
) { ) {
if (!isDynamicLayout) { final children = [
return TimelineRow.fixed( for (int i = 0; i < assets.length; i++)
dimension: tileHeight, TimelineAssetIndexWrapper(
spacing: spacing, assetIndex: assetIndex + i,
textDirection: Directionality.of(context), segmentIndex: 0, // For simplicity, using 0 for now
children: [ child: _AssetTileWidget(
for (int i = 0; i < assets.length; i++) key: ValueKey(Object.hash(assets[i].heroTag, assetIndex + i, timelineService.hashCode)),
TimelineAssetIndexWrapper( asset: assets[i],
assetIndex: assetIndex + i, 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, 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;
// 1: mean width
// 0.5: width < mean - threshold
// 1.5: width > mean + threshold
final arConfiguration = aspectRatios.map((e) {
if (e - meanAspectRatio > 0.3) return 1.5;
if (e - meanAspectRatio < -0.3) return 0.5;
return 1.0;
});
// 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
widths[index++] = ((ratio * assets.length) / sum) * tileHeight;
}
} }
final aspectRatios = assets.map((e) => (e.width ?? 1) / (e.height ?? 1)).toList();
final meanAspectRatio = aspectRatios.sum / assets.length;
// 1: mean width
// 0.5: width < mean - threshold
// 1.5: width > mean + threshold
final arConfiguration = aspectRatios.map((e) {
if (e - meanAspectRatio > 0.3) return 1.5;
if (e - meanAspectRatio < -0.3) return 0.5;
return 1.0;
});
// Normalize to get width distribution
final sum = arConfiguration.sum;
// Distribute the available width proportionally based on aspect ratio configuration
final widths = arConfiguration.map((e) => ((e * assets.length) / sum) * tileHeight).toList();
return TimelineDragRegion( return TimelineDragRegion(
child: TimelineRow( child: TimelineRow(
height: tileHeight, height: tileHeight,
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,
),
),
],
), ),
); );
} }