Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Narrow gallery layout changes to settings and migration

ashil-pilotf8347763ff39
diff --git a/mobile/apps/photos/lib/models/gallery/gallery_groups.dart b/mobile/apps/photos/lib/models/gallery/gallery_groups.dart
index 78230c30fb..0a25ec2822 100644
--- a/mobile/apps/photos/lib/models/gallery/gallery_groups.dart
+++ b/mobile/apps/photos/lib/models/gallery/gallery_groups.dart
@@ -1,4 +1,5 @@
import "dart:core";
+import "dart:math" as math;
import "package:flutter/material.dart";
import "package:logging/logging.dart";
@@ -8,9 +9,12 @@ import "package:photos/models/file/dummy_file.dart";
import "package:photos/models/file/file.dart";
import "package:photos/models/gallery/fixed_extent_grid_row.dart";
import "package:photos/models/gallery/fixed_extent_section_layout.dart";
+import "package:photos/models/gallery/flex_layout.dart";
import "package:photos/models/gallery/gallery_layout_config.dart";
import "package:photos/models/gallery/justified_grid_row.dart";
import "package:photos/models/gallery/justified_layout.dart";
+import "package:photos/models/gallery/justified_layout_strategy.dart";
+import "package:photos/models/gallery/justified_layout_tuning.dart";
import "package:photos/models/gallery/section_layout.dart";
import "package:photos/models/selected_files.dart";
import "package:photos/service_locator.dart";
@@ -63,6 +67,10 @@ class GalleryGroups {
}
}
+ // Product decision: limit how tall the preferred justified row can grow as
+ // the gallery widens.
+ static const double _maximumJustifiedTargetRowHeight = 320.0;
+
late final int crossAxisCount;
late final GalleryLayoutType layoutType;
late final List<SectionLayout> _groupLayouts;
@@ -444,6 +452,24 @@ class GalleryGroups {
List<SectionLayout> _computeJustifiedGroupLayouts() {
final stopwatch = Stopwatch()..start();
+ final strategy = localSettings.getJustifiedLayoutStrategy();
+ final flexTuning = strategy == JustifiedLayoutStrategy.flex
+ ? localSettings.getFlexLayoutTuning()
+ : FlexLayoutTuning.defaults;
+ final comfortLargeTuning = strategy == JustifiedLayoutStrategy.comfortLarge
+ ? localSettings.getComfortLargeLayoutTuning()
+ : ComfortLargeLayoutTuning.defaults;
+ final gridTargetRowHeight =
+ (widthAvailable - (crossAxisCount - 1) * spacing) / crossAxisCount;
+ final baseTargetRowHeight = gridTargetRowHeight.isFinite
+ ? math.min(gridTargetRowHeight, _maximumJustifiedTargetRowHeight)
+ : gridTargetRowHeight;
+ final targetHeightScale = switch (strategy) {
+ JustifiedLayoutStrategy.comfortLarge =>
+ comfortLargeTuning.targetHeightScale,
+ JustifiedLayoutStrategy.flex => flexTuning.targetHeightScale,
+ };
+ final targetRowHeight = baseTargetRowHeight * targetHeightScale;
final groupLayouts = <SectionLayout>[];
var currentIndex = 0;
var currentOffset = 0.0;
@@ -456,11 +482,29 @@ class GalleryGroups {
file.height,
),
);
- final rows = JustifiedLayoutCalculator.computePairedRows(
- aspectRatios: aspectRatios,
- availableWidth: widthAvailable,
- spacing: spacing,
- );
+ final rows = switch (strategy) {
+ JustifiedLayoutStrategy.comfortLarge =>
+ JustifiedLayoutCalculator.computeRows(
+ aspectRatios: aspectRatios,
+ availableWidth: widthAvailable,
+ targetRowHeight: targetRowHeight,
+ spacing: spacing,
+ maximumRowHeightFactor: comfortLargeTuning.maximumHeightFactor,
+ wideFinalMaximumRowHeightFactor:
+ comfortLargeTuning.wideFinalMaximumHeightFactor,
+ minimumLandscapeRowHeightFactor:
+ comfortLargeTuning.minimumLandscapeHeightFactor,
+ ),
+ JustifiedLayoutStrategy.flex => FlexLayoutCalculator.computeRows(
+ aspectRatios: aspectRatios,
+ availableWidth: widthAvailable,
+ targetRowHeight: targetRowHeight,
+ spacing: spacing,
+ maximumRowHeightFactor: flexTuning.maximumHeightFactor,
+ minimumNonFinalSingletonAspectRatio:
+ flexTuning.minimumNonFinalSingletonAspectRatio,
+ ),
+ };
final firstIndex = currentIndex == 0 ? currentIndex : currentIndex + 1;
final lastIndex = firstIndex + rows.length;
final minOffset = currentOffset;
diff --git a/mobile/apps/photos/lib/models/gallery/justified_layout.dart b/mobile/apps/photos/lib/models/gallery/justified_layout.dart
index c99872877f..009c11b095 100644
--- a/mobile/apps/photos/lib/models/gallery/justified_layout.dart
+++ b/mobile/apps/photos/lib/models/gallery/justified_layout.dart
@@ -111,50 +111,6 @@ class JustifiedLayoutCalculator {
const JustifiedLayoutCalculator._();
- static List<JustifiedRowLayout> computePairedRows({
- required Iterable<double> aspectRatios,
- required double availableWidth,
- required double spacing,
- }) {
- if (!availableWidth.isFinite || availableWidth <= 0) {
- throw ArgumentError.value(availableWidth, "availableWidth");
- }
- if (!spacing.isFinite || spacing < 0 || spacing >= availableWidth) {
- throw ArgumentError.value(spacing, "spacing");
- }
- final ratios = aspectRatios
- .map((ratio) {
- return ratio.isFinite && ratio > 0
- ? ratio.clamp(_minimumAspectRatio, _maximumAspectRatio).toDouble()
- : 1.0;
- })
- .toList(growable: false);
- final rows = <JustifiedRowLayout>[];
- var offset = 0.0;
- for (var firstIndex = 0; firstIndex < ratios.length; firstIndex += 2) {
- final lastIndex = math.min(firstIndex + 1, ratios.length - 1);
- final rowRatios = ratios.sublist(firstIndex, lastIndex + 1);
- final contentWidth = availableWidth - (rowRatios.length - 1) * spacing;
- final ratioSum = rowRatios.fold(0.0, (sum, ratio) => sum + ratio);
- final height = rowRatios.length == 1
- ? math.min(contentWidth / ratioSum, availableWidth / 2)
- : contentWidth / ratioSum;
- rows.add(
- JustifiedRowLayout(
- firstIndex: firstIndex,
- lastIndex: lastIndex,
- minOffset: offset,
- height: height,
- itemWidths: rowRatios
- .map((ratio) => ratio * height)
- .toList(growable: false),
- ),
- );
- offset += height + spacing;
- }
- return rows;
- }
-
static double aspectRatioForDimensions(int width, int height) {
if (width <= 0 || height <= 0) return 1;
return (width / height)
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
index 213fefea9e..e80c3151cf 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
@@ -31,7 +31,6 @@ import "package:photos/ui/viewer/gallery/component/sectioned_sliver_list.dart";
import 'package:photos/ui/viewer/gallery/empty_state.dart';
import "package:photos/ui/viewer/gallery/gallery_app_bar_config.dart";
import "package:photos/ui/viewer/gallery/gallery_app_bar_widget.dart";
-import "package:photos/ui/viewer/gallery/layout_settings.dart";
import "package:photos/ui/viewer/gallery/scrollbar/custom_scroll_bar.dart";
import "package:photos/ui/viewer/gallery/state/boundary_reporter_mixin.dart";
import "package:photos/ui/viewer/gallery/state/gallery_boundaries_provider.dart";
@@ -183,11 +182,6 @@ class GalleryState extends State<Gallery> {
InheritedGalleryBoundaries? _boundariesProvider;
late String _automationScrollIdentifier;
- bool get _showLayoutControls =>
- widget.showGallerySettingsCTA &&
- !widget.disableScroll &&
- !widget.limitSelectionToOne;
-
@override
void initState() {
super.initState();
@@ -399,7 +393,7 @@ class GalleryState extends State<Gallery> {
groupHeaderExtent: groupHeaderExtent!,
showSelectAll: widget.showSelectAll,
limitSelectionToOne: widget.limitSelectionToOne,
- showGallerySettingsCTA: _showLayoutControls,
+ showGallerySettingsCTA: widget.showGallerySettingsCTA,
groupHeaderAction: widget.groupHeaderAction,
layoutTypeOverride: widget.layoutTypeOverride,
justifiedLayoutAvailable: isJustifiedLayoutAvailable,
@@ -1081,13 +1075,11 @@ class GalleryState extends State<Gallery> {
widget.showSelectAll &&
!widget.limitSelectionToOne,
scrollbarInUseNotifier: scrollBarInUseNotifier,
- showGallerySettingsCTA: _showLayoutControls,
+ showGallerySettingsCTA:
+ widget.showGallerySettingsCTA,
groupHeaderAction: widget.groupHeaderAction,
)
: const SizedBox.shrink(),
- if (_showLayoutControls &&
- !groups.groupType.showGroupHeader())
- _FloatingLayoutControl(topInset: appBarPinnedHeight),
],
),
),
@@ -1125,21 +1117,6 @@ class _GalleryAppBarScrollBody extends StatelessWidget {
}
}
-class _FloatingLayoutControl extends StatelessWidget {
- const _FloatingLayoutControl({this.topInset = 0});
-
- final double topInset;
-
- @override
- Widget build(BuildContext context) {
- return Positioned(
- right: 16,
- top: topInset + 16,
- child: const FloatingGalleryLayoutButton(),
- );
- }
-}
-
class PinnedGroupHeader extends StatefulWidget {
final ScrollController scrollController;
final GalleryGroups galleryGroups;
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/layout_settings.dart b/mobile/apps/photos/lib/ui/viewer/gallery/layout_settings.dart
index 53ac1f57c5..0d36cb485e 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/layout_settings.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/layout_settings.dart
@@ -14,39 +14,3 @@ class GalleryLayoutSettings extends StatelessWidget {
);
}
}
-
-class FloatingGalleryLayoutButton extends StatelessWidget {
- const FloatingGalleryLayoutButton({super.key});
-
- @override
- Widget build(BuildContext context) {
- return Semantics(
- button: true,
- label: context.strings.layout,
- child: DecoratedBox(
- decoration: BoxDecoration(
- color: context.componentColors.fillLight,
- shape: BoxShape.circle,
- boxShadow: const [
- BoxShadow(
- color: Color(0x14000000),
- blurRadius: 8,
- offset: Offset(0, 2),
- ),
- ],
- ),
- child: IconButtonComponent(
- icon: const Icon(Icons.more_vert_outlined),
- variant: IconButtonComponentVariant.circular,
- size: 48,
- tooltip: context.strings.layout,
- shouldSurfaceExecutionStates: false,
- onTap: () => showBottomSheetComponent<void>(
- context: context,
- builder: (_) => const GalleryLayoutSettings(),
- ),
- ),
- ),
- );
- }
-}
diff --git a/mobile/apps/photos/lib/ui/viewer/location/dynamic_location_gallery_widget.dart b/mobile/apps/photos/lib/ui/viewer/location/dynamic_location_gallery_widget.dart
index a573a5acce..8a3fa9f7cd 100644
--- a/mobile/apps/photos/lib/ui/viewer/location/dynamic_location_gallery_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/location/dynamic_location_gallery_widget.dart
@@ -1,14 +1,11 @@
-import "dart:async";
import "dart:developer" as dev;
+import "dart:math";
import "package:flutter/material.dart";
import "package:photos/core/constants.dart";
-import "package:photos/core/event_bus.dart";
import "package:photos/db/files_db.dart";
-import "package:photos/events/gallery_layout_changed_event.dart";
import 'package:photos/models/file/file.dart';
import "package:photos/models/file_load_result.dart";
-import "package:photos/models/gallery/justified_layout.dart";
import "package:photos/service_locator.dart";
import "package:photos/services/collections_service.dart";
import "package:photos/services/filter/db_filters.dart";
@@ -35,7 +32,7 @@ class DynamicLocationGalleryWidget extends StatefulWidget {
class _DynamicLocationGalleryWidgetState
extends State<DynamicLocationGalleryWidget> {
late final Future<FileLoadResult> fileLoadResult;
- late final StreamSubscription<GalleryLayoutChangedEvent> _layoutSubscription;
+ double heightOfGallery = 0;
@override
void initState() {
@@ -53,20 +50,9 @@ class _DynamicLocationGalleryWidgetState
),
);
- _layoutSubscription = Bus.instance.on<GalleryLayoutChangedEvent>().listen((
- _,
- ) {
- if (mounted) setState(() {});
- });
super.initState();
}
- @override
- void dispose() {
- _layoutSubscription.cancel();
- super.dispose();
- }
-
@override
Widget build(BuildContext context) {
const galleryFilesLimit = 1000;
@@ -102,7 +88,10 @@ class _DynamicLocationGalleryWidgetState
builder: (context, constrains) {
return SizedBox(
height: _galleryHeight(
- (snapshot.data as FileLoadResult).files,
+ min(
+ (widget.memoriesCountNotifier.value ?? 0),
+ galleryFilesLimit,
+ ),
constrains.maxWidth,
),
child: GalleryFilesState(
@@ -120,6 +109,7 @@ class _DynamicLocationGalleryWidgetState
},
tagPrefix: widget.tagPrefix,
enableFileGrouping: false,
+ layoutTypeOverride: GalleryLayoutType.grid,
showSelectAll: false,
),
),
@@ -134,20 +124,7 @@ class _DynamicLocationGalleryWidgetState
);
}
- double _galleryHeight(List<EnteFile> files, double widthOfGrid) {
- if (localSettings.getGalleryLayoutType() == GalleryLayoutType.justified) {
- final rows = JustifiedLayoutCalculator.computePairedRows(
- aspectRatios: files.map(
- (file) => JustifiedLayoutCalculator.aspectRatioForDimensions(
- file.width,
- file.height,
- ),
- ),
- availableWidth: widthOfGrid,
- spacing: galleryGridSpacing,
- );
- return (rows.isEmpty ? 0 : rows.last.maxOffset) + 120;
- }
+ double _galleryHeight(int fileCount, double widthOfGrid) {
final photoGridSize = localSettings.getPhotoGridSize();
final totalWhiteSpaceBetweenPhotos =
galleryGridSpacing * (photoGridSize - 1);
@@ -155,7 +132,7 @@ class _DynamicLocationGalleryWidgetState
final thumbnailHeight =
((widthOfGrid - totalWhiteSpaceBetweenPhotos) / photoGridSize);
- final numberOfRows = (files.length / photoGridSize).ceil();
+ final numberOfRows = (fileCount / photoGridSize).ceil();
final galleryHeight =
(thumbnailHeight * numberOfRows) +
diff --git a/mobile/apps/photos/test/models/gallery_groups_justified_test.dart b/mobile/apps/photos/test/models/gallery_groups_justified_test.dart
index aa46567a68..5560a6c651 100644
--- a/mobile/apps/photos/test/models/gallery_groups_justified_test.dart
+++ b/mobile/apps/photos/test/models/gallery_groups_justified_test.dart
@@ -123,11 +123,7 @@ void main() {
for (final file in expectedFiles) {
final fileOffset = groups.getOffsetOfFile(file);
expect(fileOffset, isNotNull);
- final fileIndex = expectedFiles.indexOf(file);
- expect(
- groups.getFileAtScrollOffset(fileOffset!),
- same(expectedFiles[fileIndex - fileIndex % 2]),
- );
+ expect(groups.getFileAtScrollOffset(fileOffset!), same(file));
expect(
groups.getOffsetOfGroupContainingFile(file),
closeTo(justifiedSection.minOffset, 1e-9),
@@ -140,41 +136,119 @@ void main() {
}
});
- test(
- "justified always pairs photos independently of the saved grid count",
- () async {
- final files = List.generate(
- 5,
- (index) => _file(
- index: index,
- creationTime: DateTime(2026, 8, 19).microsecondsSinceEpoch,
- width: index.isEven ? 3 : 1,
- height: index.isEven ? 2 : 2,
- ),
- );
- for (final count in [3, 6]) {
- await localSettings.setPhotoGridSize(count);
- final groups = _galleryGroups(
- files: files,
- groupType: GroupType.none,
- groupHeaderExtent: GalleryGroups.spacing,
- widthAvailable: 402,
- );
- expect(groups.crossAxisCount, 2);
- final section = groups.groupLayouts.single as JustifiedSectionLayout;
- expect(section.rows.map((row) => row.itemWidths.length), [2, 2, 1]);
- _expectRowsCoverFiles(section, files.length);
- for (final row in section.rows.take(2)) {
- expect(
- row.itemWidths.reduce((a, b) => a + b) + GalleryGroups.spacing,
- closeTo(402, 1e-9),
- );
- expect(row.itemWidths.first / row.itemWidths.last, closeTo(3, 1e-9));
- }
- expect(section.rows.last.height, lessThanOrEqualTo(201));
- }
- },
- );
+ test("routes justified galleries through the selected strategy", () async {
+ final files = List.generate(
+ 4,
+ (index) => _file(
+ index: index,
+ creationTime: DateTime(2026, 8, 19).microsecondsSinceEpoch,
+ width: 9,
+ height: 16,
+ ),
+ );
+ await localSettings.setPhotoGridSize(3);
+ await localSettings.setComfortLargeLayoutTuningValue(
+ ComfortLargeLayoutTuningField.targetHeightScale,
+ 1,
+ );
+ GalleryGroups groups() => _galleryGroups(
+ files: files,
+ groupType: GroupType.none,
+ groupHeaderExtent: GalleryGroups.spacing,
+ widthAvailable: 402,
+ );
+ final comfortLarge = groups().groupLayouts.single as JustifiedSectionLayout;
+ expect(comfortLarge.rows.map((row) => row.itemWidths.length), [2, 2]);
+ await localSettings.setJustifiedLayoutStrategy(
+ JustifiedLayoutStrategy.flex,
+ );
+ await localSettings.setFlexLayoutTuningValue(
+ FlexLayoutTuningField.targetHeightScale,
+ 1,
+ );
+ final flex = groups().groupLayouts.single as JustifiedSectionLayout;
+ expect(flex.rows.map((row) => row.itemWidths.length), [3, 1]);
+ _expectRowsCoverFiles(flex, files.length);
+ });
+
+ test("routes Flex with its non-final singleton tuning", () async {
+ final files = List<EnteFile>.generate(
+ 3,
+ (index) => _file(
+ index: index,
+ creationTime: DateTime(2026, 8, 19).microsecondsSinceEpoch,
+ width: 16,
+ height: 9,
+ ),
+ );
+ await localSettings.setPhotoGridSize(3);
+ await localSettings.setJustifiedLayoutStrategy(
+ JustifiedLayoutStrategy.flex,
+ );
+
+ JustifiedSectionLayout section() =>
+ _galleryGroups(
+ files: files,
+ groupType: GroupType.none,
+ groupHeaderExtent: GalleryGroups.spacing,
+ widthAvailable: 402,
+ ).groupLayouts.single
+ as JustifiedSectionLayout;
+
+ expect(section().rows.map((row) => row.itemWidths.length), [1, 1, 1]);
+ await localSettings.setFlexLayoutTuningValue(
+ FlexLayoutTuningField.minimumNonFinalSingletonAspectRatio,
+ 2,
+ );
+ final constrainedRows = section().rows;
+ expect(constrainedRows.map((row) => row.itemWidths.length), [2, 1]);
+ });
+
+ test("keeps layout tuning separate for Flex and Comfort Large", () async {
+ final file = _file(
+ index: 0,
+ creationTime: DateTime(2026, 8, 19).microsecondsSinceEpoch,
+ width: 1,
+ height: 1,
+ );
+ await localSettings.setPhotoGridSize(3);
+ double rowHeight() {
+ final section =
+ _galleryGroups(
+ files: [file],
+ groupType: GroupType.none,
+ groupHeaderExtent: GalleryGroups.spacing,
+ widthAvailable: 1024,
+ ).groupLayouts.single
+ as JustifiedSectionLayout;
+ return section.rows.single.height;
+ }
+
+ expect(
+ rowHeight(),
+ 320 * ComfortLargeLayoutTuning.defaults.targetHeightScale,
+ );
+
+ await localSettings.setComfortLargeLayoutTuningValue(
+ ComfortLargeLayoutTuningField.targetHeightScale,
+ 1.25,
+ );
+ expect(rowHeight(), 400);
+
+ await localSettings.setJustifiedLayoutStrategy(
+ JustifiedLayoutStrategy.flex,
+ );
+ final defaultFlexHeight =
+ 320 *
+ FlexLayoutTuning.defaults.targetHeightScale *
+ FlexLayoutTuning.defaults.maximumHeightFactor;
+ expect(rowHeight(), defaultFlexHeight);
+ await localSettings.setFlexLayoutTuningValue(
+ FlexLayoutTuningField.maximumHeightFactor,
+ 2,
+ );
+ expect(rowHeight(), 320 * FlexLayoutTuning.defaults.targetHeightScale * 2);
+ });
test(
"headerless justified remains one continuous group past grid chunks",
@@ -189,8 +263,8 @@ void main() {
(index) => _file(
index: index,
creationTime: DateTime(2026, 8, 19).microsecondsSinceEpoch,
- width: 3,
- height: 2,
+ width: 2,
+ height: 3,
),
growable: false,
);
@@ -215,7 +289,11 @@ void main() {
expect(section.bodyMinOffset, GalleryGroups.spacing);
_expectRowsCoverFiles(section, fileCount);
- expect(section.rows, hasLength(fileCount ~/ 2));
+ final rowAcrossLegacyBoundary = section.rows.singleWhere(
+ (row) => row.firstIndex <= 19 && row.lastIndex >= 20,
+ );
+ expect(rowAcrossLegacyBoundary.firstIndex, 18);
+ expect(rowAcrossLegacyBoundary.lastIndex, 20);
for (final row in section.rows) {
final firstFileInRow = files[row.firstIndex];
@@ -230,6 +308,39 @@ void main() {
},
);
+ test(
+ "caps the Justified target independently of the remembered Grid count",
+ () async {
+ final file = _file(
+ index: 0,
+ creationTime: DateTime(2026, 8, 19).microsecondsSinceEpoch,
+ width: 1,
+ height: 1,
+ );
+ double rowHeight() {
+ final section =
+ _galleryGroups(
+ files: [file],
+ groupType: GroupType.none,
+ groupHeaderExtent: GalleryGroups.spacing,
+ widthAvailable: 1024,
+ ).groupLayouts.single
+ as JustifiedSectionLayout;
+ return section.rows.single.height;
+ }
+
+ await localSettings.setPhotoGridSize(3);
+ await localSettings.setComfortLargeLayoutTuningValue(
+ ComfortLargeLayoutTuningField.targetHeightScale,
+ 1,
+ );
+ expect(rowHeight(), 320);
+
+ await localSettings.setPhotoGridSize(4);
+ expect(rowHeight(), 320);
+ },
+ );
+
testWidgets("justified rows request large thumbnails for every tile", (
tester,
) async {
diff --git a/mobile/apps/photos/test/ui/viewer/gallery/gallery_layout_changed_event_test.dart b/mobile/apps/photos/test/ui/viewer/gallery/gallery_layout_changed_event_test.dart
index edda8b9d34..aef0fccb0b 100644
--- a/mobile/apps/photos/test/ui/viewer/gallery/gallery_layout_changed_event_test.dart
+++ b/mobile/apps/photos/test/ui/viewer/gallery/gallery_layout_changed_event_test.dart
@@ -176,6 +176,7 @@ void main() {
(_) => events++,
);
addTearDown(subscription.cancel);
+ await localSettings.setInternalUserDisabled(true);
for (final quickMenu in [true, false]) {
await localSettings.setGalleryLayoutType(GalleryLayoutType.grid);
await localSettings.setPhotoGridSize(5);
@@ -260,140 +261,6 @@ void main() {
},
);
- testWidgets(
- "only opted-in galleries show a header CTA or floating Layout control",
- (tester) async {
- final files = List.generate(120, _justifiedTestFile);
- for (final groupType in [GroupType.day, GroupType.none]) {
- await tester.pumpWidget(
- MaterialApp(
- theme: lightThemeData,
- localizationsDelegates: StringsLocalizations.localizationsDelegates,
- supportedLocales: StringsLocalizations.supportedLocales,
- home: Scaffold(
- body: _galleryHost(
- Gallery(
- asyncLoader: (start, end, {limit, asc}) async =>
- FileLoadResult(files, false),
- initialFiles: files,
- tagPrefix: "default_layout_cta_",
- groupType: groupType,
- showSelectAll: false,
- ),
- ),
- ),
- ),
- );
- await tester.pumpAndSettle();
- await tester.pump(const Duration(milliseconds: 750));
- await tester.pump();
- if (groupType == GroupType.day) {
- expect(find.byType(GroupHeaderWidget), findsWidgets);
- }
- expect(find.byType(FloatingGalleryLayoutButton), findsNothing);
- expect(
- find.byWidgetPredicate(
- (widget) =>
- widget is GroupHeaderWidget &&
- widget.showGalleryLayoutSettingCTA,
- ),
- findsNothing,
- );
- await tester.pumpWidget(const SizedBox.shrink());
- await tester.pumpAndSettle();
- }
- for (final pinnedDisabled in [false, true]) {
- final galleryKey = GlobalKey<GalleryState>();
- await tester.pumpWidget(
- MaterialApp(
- theme: lightThemeData,
- localizationsDelegates: StringsLocalizations.localizationsDelegates,
- supportedLocales: StringsLocalizations.supportedLocales,
- home: Scaffold(
- body: _galleryHost(
- Gallery(
- key: galleryKey,
- asyncLoader: (start, end, {limit, asc}) async =>
- FileLoadResult(files, false),
- initialFiles: files,
- tagPrefix: "layout_cta_",
- header: const SizedBox(height: 120),
- groupType: GroupType.day,
- disablePinnedGroupHeader: pinnedDisabled,
- showSelectAll: false,
- showGallerySettingsCTA: true,
- ),
- ),
- ),
- ),
- );
- await tester.pumpAndSettle();
- await tester.pump(const Duration(milliseconds: 750));
- await tester.pump();
- expect(find.byType(FloatingGalleryLayoutButton), findsNothing);
- expect(
- find.byWidgetPredicate(
- (widget) =>
- widget is GroupHeaderWidget &&
- widget.showGalleryLayoutSettingCTA,
- ),
- findsWidgets,
- );
- if (!pinnedDisabled) {
- final scrollable = find
- .descendant(
- of: find.byType(Gallery),
- matching: find.byType(Scrollable),
- )
- .first;
- tester.state<ScrollableState>(scrollable).position.jumpTo(300);
- await tester.pumpAndSettle();
- expect(find.byType(FloatingGalleryLayoutButton), findsNothing);
- expect(
- find.byWidgetPredicate(
- (widget) =>
- widget is GroupHeaderWidget &&
- widget.isPinnedHeader &&
- widget.showGalleryLayoutSettingCTA,
- ),
- findsOneWidget,
- );
- }
- await tester.pumpWidget(const SizedBox.shrink());
- await tester.pumpAndSettle();
- }
- await tester.pumpWidget(
- MaterialApp(
- theme: lightThemeData,
- localizationsDelegates: StringsLocalizations.localizationsDelegates,
- supportedLocales: StringsLocalizations.supportedLocales,
- home: Scaffold(
- body: _galleryHost(
- Gallery(
- asyncLoader: (start, end, {limit, asc}) async =>
- FileLoadResult(files, false),
- initialFiles: files,
- tagPrefix: "headerless_layout_cta_",
- groupType: GroupType.none,
- showSelectAll: false,
- showGallerySettingsCTA: true,
- ),
- ),
- ),
- ),
- );
- await tester.pumpAndSettle();
- final galleryRect = tester.getRect(find.byType(Gallery));
- final buttonRect = tester.getRect(
- find.byType(FloatingGalleryLayoutButton),
- );
- expect(buttonRect.top, closeTo(galleryRect.top + 16, 0.001));
- expect(buttonRect.right, closeTo(galleryRect.right - 16, 0.001));
- await tester.pumpWidget(const SizedBox.shrink());
- await tester.pumpAndSettle();
- },
- );
-
testWidgets("Flex tuning accepts arbitrary decimals and resets one field", (
tester,
) async {