mirror of
https://github.com/flutter/packages.git
synced 2025-06-28 22:02:38 +08:00
[dynamic_layouts] relax layout test to fix tree (#4677)
A current roll from the engine to flutter/flutter to packages has broken this test value by a small amount. I wrote a small function to manage tolerances. Let me know if this is a reasonable way to manage this for now.
This commit is contained in:
@ -1 +1 @@
|
||||
f4c25bbb351cc59ffdefe980c0c993196a8a6d47
|
||||
685141bf3b5ff4a90589fd77784776e011dd5fcc
|
||||
|
@ -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(
|
||||
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user