Reputation: 303
In my app, I've noticed some widgets generate overflow exception in a particular situation: when there are increased font sizes preempted by the user via Accessibility options in the iOS/Android.
I would like to widget test these widgets, by passing a parameter to increase the font size like OS selected, and check if there are any overflows.
This kind of test would be similar to widget test in different screen sizes, in which is possible to set the physical size like below:
import 'package:flutter_test/flutter_test.dart';
(...)
testWidgets('test overflow on iPhone SE 1 gen', (tester) async {
tester.binding.window.physicalSizeTestValue = Size(320.0, 568.0);
(...)
}
Are there any recommended practices over widget testing with highly increased font sizes as an accessibility option in Flutter?
Upvotes: 3
Views: 796
Reputation: 876
Since version 3.10.0, the window singleton is deprecated( https://docs.flutter.dev/release/breaking-changes/window-singleton). Therefore, the textScaleFactor must now be set as follows:
tester.platformDispatcher.textScaleFactorTestValue = 2.0;
Upvotes: 4
Reputation: 381
You can provide a new MediaQuery when you pump your widget:
await tester.pumpWidget(MaterialApp(
home: Material(
child: Builder(
builder: (context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.5),
child: YourWidgetHere(),
);
}
),
),
));
Update:
It may be more appropriate to update the test scale factor, although I haven't tested it:
tester.binding.window.platformDispatcher.textScaleFactorTestValue = 2.5;
Upvotes: 1