fixed section layout when there is no header
This commit is contained in:
parent
b32a7747f6
commit
1478f1add3
2 changed files with 31 additions and 32 deletions
|
@ -2,7 +2,6 @@ import 'dart:math';
|
||||||
|
|
||||||
import 'package:aves/labs/sliver_known_extent_list.dart';
|
import 'package:aves/labs/sliver_known_extent_list.dart';
|
||||||
import 'package:aves/model/collection_lens.dart';
|
import 'package:aves/model/collection_lens.dart';
|
||||||
import 'package:aves/utils/constants.dart';
|
|
||||||
import 'package:aves/widgets/album/collection_section.dart';
|
import 'package:aves/widgets/album/collection_section.dart';
|
||||||
import 'package:aves/widgets/album/grid/header_generic.dart';
|
import 'package:aves/widgets/album/grid/header_generic.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
@ -31,21 +30,12 @@ class CollectionListSliver extends StatelessWidget {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final sectionLayouts = <SectionLayout>[];
|
final sectionLayouts = <SectionLayout>[];
|
||||||
final sectionKeys = collection.sections.keys.toList();
|
final sectionKeys = collection.sections.keys.toList();
|
||||||
final headerPadding = TitleSectionHeader.padding;
|
|
||||||
var currentIndex = 0, currentOffset = 0.0;
|
var currentIndex = 0, currentOffset = 0.0;
|
||||||
sectionKeys.forEach((sectionKey) {
|
sectionKeys.forEach((sectionKey) {
|
||||||
final sectionEntryCount = collection.sections[sectionKey].length;
|
final sectionEntryCount = collection.sections[sectionKey].length;
|
||||||
final sectionChildCount = 1 + (sectionEntryCount / columnCount).ceil();
|
final sectionChildCount = 1 + (sectionEntryCount / columnCount).ceil();
|
||||||
|
|
||||||
var headerExtent = 0.0;
|
final headerExtent = showHeader ? SectionHeader.computeHeaderExtent(collection, sectionKey, scrollableWidth) : 0.0;
|
||||||
if (showHeader) {
|
|
||||||
// only compute height for album headers, as they're the only likely ones to split on multiple lines
|
|
||||||
if (sectionKey is String) {
|
|
||||||
final text = collection.source.getUniqueAlbumName(sectionKey);
|
|
||||||
headerExtent = SectionLayout.computeHeaderExtent(text, scrollableWidth - headerPadding.horizontal);
|
|
||||||
}
|
|
||||||
headerExtent = max(headerExtent, TitleSectionHeader.leadingDimension) + headerPadding.vertical;
|
|
||||||
}
|
|
||||||
|
|
||||||
final sectionFirstIndex = currentIndex;
|
final sectionFirstIndex = currentIndex;
|
||||||
currentIndex += sectionChildCount;
|
currentIndex += sectionChildCount;
|
||||||
|
@ -66,16 +56,14 @@ class CollectionListSliver extends StatelessWidget {
|
||||||
tileExtent: tileExtent,
|
tileExtent: tileExtent,
|
||||||
builder: (context, listIndex) {
|
builder: (context, listIndex) {
|
||||||
listIndex -= sectionFirstIndex;
|
listIndex -= sectionFirstIndex;
|
||||||
if (showHeader) {
|
if (listIndex == 0) {
|
||||||
if (listIndex == 0) {
|
return SectionHeader(
|
||||||
return SectionHeader(
|
collection: collection,
|
||||||
collection: collection,
|
sections: collection.sections,
|
||||||
sections: collection.sections,
|
sectionKey: sectionKey,
|
||||||
sectionKey: sectionKey,
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
listIndex--;
|
|
||||||
}
|
}
|
||||||
|
listIndex--;
|
||||||
|
|
||||||
final section = collection.sections[sectionKey];
|
final section = collection.sections[sectionKey];
|
||||||
final minEntryIndex = listIndex * columnCount;
|
final minEntryIndex = listIndex * columnCount;
|
||||||
|
@ -153,16 +141,4 @@ class SectionLayout {
|
||||||
scrollOffset -= minOffset + headerExtent;
|
scrollOffset -= minOffset + headerExtent;
|
||||||
return firstIndex + (scrollOffset < 0 ? 0 : (scrollOffset / tileExtent).ceil() - 1);
|
return firstIndex + (scrollOffset < 0 ? 0 : (scrollOffset / tileExtent).ceil() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO TLAD cache header extent computation?
|
|
||||||
static double computeHeaderExtent(String text, double scrollableWidth) {
|
|
||||||
final para = RenderParagraph(
|
|
||||||
TextSpan(
|
|
||||||
text: text,
|
|
||||||
style: Constants.titleTextStyle,
|
|
||||||
),
|
|
||||||
textDirection: TextDirection.ltr,
|
|
||||||
)..layout(BoxConstraints(maxWidth: scrollableWidth), parentUsesSize: true);
|
|
||||||
return para.getMaxIntrinsicHeight(scrollableWidth);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:aves/model/collection_lens.dart';
|
import 'package:aves/model/collection_lens.dart';
|
||||||
import 'package:aves/model/image_entry.dart';
|
import 'package:aves/model/image_entry.dart';
|
||||||
import 'package:aves/utils/constants.dart';
|
import 'package:aves/utils/constants.dart';
|
||||||
|
@ -6,6 +8,7 @@ import 'package:aves/widgets/album/grid/header_date.dart';
|
||||||
import 'package:aves/widgets/common/fx/outlined_text.dart';
|
import 'package:aves/widgets/common/fx/outlined_text.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/rendering.dart';
|
||||||
|
|
||||||
class SectionHeader extends StatelessWidget {
|
class SectionHeader extends StatelessWidget {
|
||||||
final CollectionLens collection;
|
final CollectionLens collection;
|
||||||
|
@ -59,6 +62,26 @@ class SectionHeader extends StatelessWidget {
|
||||||
albumName: collection.source.getUniqueAlbumName(folderPath),
|
albumName: collection.source.getUniqueAlbumName(folderPath),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO TLAD cache header extent computation?
|
||||||
|
static double computeHeaderExtent(CollectionLens collection, dynamic sectionKey, double scrollableWidth) {
|
||||||
|
var headerExtent = 0.0;
|
||||||
|
if (sectionKey is String) {
|
||||||
|
// only compute height for album headers, as they're the only likely ones to split on multiple lines
|
||||||
|
final text = collection.source.getUniqueAlbumName(sectionKey);
|
||||||
|
final maxWidth = scrollableWidth - TitleSectionHeader.padding.horizontal;
|
||||||
|
final para = RenderParagraph(
|
||||||
|
TextSpan(
|
||||||
|
text: text,
|
||||||
|
style: Constants.titleTextStyle,
|
||||||
|
),
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
)..layout(BoxConstraints(maxWidth: maxWidth), parentUsesSize: true);
|
||||||
|
headerExtent = para.getMaxIntrinsicHeight(maxWidth);
|
||||||
|
}
|
||||||
|
headerExtent = max(headerExtent, TitleSectionHeader.leadingDimension) + TitleSectionHeader.padding.vertical;
|
||||||
|
return headerExtent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TitleSectionHeader extends StatelessWidget {
|
class TitleSectionHeader extends StatelessWidget {
|
||||||
|
|
Loading…
Reference in a new issue