From ce715c58665347e2feae1188af1defd5d4d42673 Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Wed, 18 Sep 2019 19:43:05 +0900 Subject: [PATCH] info: improved metadata split in landscape --- .../fullscreen/info/metadata_section.dart | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/widgets/fullscreen/info/metadata_section.dart b/lib/widgets/fullscreen/info/metadata_section.dart index e843e08f4..68c6a48da 100644 --- a/lib/widgets/fullscreen/info/metadata_section.dart +++ b/lib/widgets/fullscreen/info/metadata_section.dart @@ -47,16 +47,19 @@ class MetadataSectionState extends State { Widget content; if (MediaQuery.of(context).size.width > 400) { - final threshold = (2 * directoryNames.length + directoryNames.map((k) => metadataMap[k].length).reduce((v, e) => v + e)) / 2; final first = [], second = []; - var processed = 0; - for (int i = 0; i < directoryNames.length; i++) { - final directoryName = directoryNames[i]; - if (processed <= threshold) + var firstItemCount = 0, secondItemCount = 0; + var firstIndex = 0, secondIndex = directoryNames.length - 1; + while (firstIndex <= secondIndex) { + if (firstItemCount <= secondItemCount) { + final directoryName = directoryNames[firstIndex++]; first.add(directoryName); - else - second.add(directoryName); - processed += 2 + metadataMap[directoryName].length; + firstItemCount += 2 + metadataMap[directoryName].length; + } else { + final directoryName = directoryNames[secondIndex--]; + second.insert(0, directoryName); + secondItemCount += 2 + metadataMap[directoryName].length; + } } content = Row( crossAxisAlignment: CrossAxisAlignment.start,