Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ci/flutter_master.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f4c25bbb351cc59ffdefe980c0c993196a8a6d47
685141bf3b5ff4a90589fd77784776e011dd5fcc
56 changes: 35 additions & 21 deletions packages/dynamic_layouts/example/test/wrap_example_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,33 @@
// found in the LICENSE file.

import 'package:example/wrap_layout_example.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
void withinTolerance(Offset actual, Offset expected, double tolerance) {
expect(
actual.dx,
(double actual) => actual <= expected.dx + tolerance,
reason: '${actual.dx} <= ${expected.dx + tolerance}',
);
expect(
actual.dx,
(double actual) => actual >= expected.dx - tolerance,
reason: '${actual.dx} >= ${expected.dx - tolerance}',
);
expect(
actual.dy,
(double actual) => actual <= expected.dy + tolerance,
reason: '${actual.dy} <= ${expected.dy + tolerance}',
);
expect(
actual.dy,
(double actual) => actual >= expected.dy - tolerance,
reason: '${actual.dy} >= ${expected.dy - tolerance}',
);
}

testWidgets('Check that the children are layed out.',
(WidgetTester tester) async {
const MaterialApp app = MaterialApp(
Expand All @@ -25,27 +47,19 @@ void main() {

// Material 3 changes the expected layout positioning.
final bool usesMaterial3 = (app.theme ?? ThemeData.light()).useMaterial3;
final Offset offset0 = usesMaterial3
? Offset(0.0, _getExpectedYOffset(91.0))
: const Offset(0.0, 103.0);
final Offset offset1 = usesMaterial3
? Offset(65.0, _getExpectedYOffset(121.0))
: const Offset(66.0, 124.0);
final Offset offset3 = usesMaterial3
? Offset(270.0, _getExpectedYOffset(171.0))
: const Offset(271.0, 174.0);
final Offset offset4 = usesMaterial3
? Offset(380.0, _getExpectedYOffset(221.0))
: const Offset(381.0, 224.0);
final Offset offset0 =
usesMaterial3 ? const Offset(0.0, 91.0) : const Offset(0.0, 103.0);
final Offset offset1 =
usesMaterial3 ? const Offset(65.0, 121.0) : const Offset(66.0, 124.0);
final Offset offset3 =
usesMaterial3 ? const Offset(270.0, 171.0) : const Offset(271.0, 174.0);
final Offset offset4 =
usesMaterial3 ? const Offset(380.0, 221.0) : const Offset(381.0, 224.0);

// See if they are in expected position.
expect(tester.getTopLeft(find.text('Index 0')), offset0);
expect(tester.getTopLeft(find.text('Index 1')), offset1);
expect(tester.getTopLeft(find.text('Index 3')), offset3);
expect(tester.getTopLeft(find.text('Index 4')), offset4);
withinTolerance(tester.getTopLeft(find.text('Index 0')), offset0, 0.2);
withinTolerance(tester.getTopLeft(find.text('Index 1')), offset1, 0.2);
withinTolerance(tester.getTopLeft(find.text('Index 3')), offset3, 0.2);
withinTolerance(tester.getTopLeft(find.text('Index 4')), offset4, 0.2);
});
}

double _getExpectedYOffset(double nonWeb) {
return kIsWeb ? nonWeb - 0.5 : nonWeb;
}