You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Document the flutter_test dimensions and describe tricks for testing other dimensions #12994
Currently the size is fixed at 800 x 600, which makes it impossible to test behavior that happens only in portrait mode, as well as other size-dependent behavior.
That will make AutomatedTestWidgetsFlutterBinding automatically pick up the desired resolution.
We would need to update LiveTestWidgetsFlutterBinding to provide a hook whereby the developer could specify the fixed resolution in which they want to run. Otherwise, even though the real test was run in a resolution specified by the developer, a flutter run invocation of that test would yield a different resolution.
Not sure how much this is related but it would be useful if we could take full-page screenshots of entire widgets for screenshot tests. For example: if you have a ListView that extends beyond the default viewport, the screenshot would capture the entire ListView. Also, if you have a widget less than the default viewport, it could capture an image that's just that widget's size.
Thanks, Todd. That's exactly what I was looking for.
Ian, I guess maybe what I'm asking for just not possible to implement with the design of ListViews. I'm basically asking for what you describe in your second paragraph but for it to somehow know how large the screen is. Maybe we could create our own implementation by scrolling the screen down until it won't scroll anymore and determining the height. cc @johnfesa
@Hixie, @paolosoares reports that he'd like to not just change the size of the produced image -- he'd like to change the constraints so that the widget lays out differently.
Just wrap the widget under test in a SizedBox (contained in a Center) with the given size. Optionally add a MediaQuery in there too if that matters.
For simulating screen rotation, it seems that the SizedBox + MediaQuery approach might not behave quite like an actual screen rotation on a device. I've observed an actual screen rotation triggering Layer.attach without triggering Layer.addToScene, but changing the dimensions of a SizedBox seems to trigger both.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.
Activity
tvolkert commentedon Nov 13, 2017
Potential options:
flutter_testerthat affect the screen resolution in test_runner.ccMakeAutomatedTestWidgetsFlutterBindingoverridecreateViewConfiguration()(likeLiveTestWidgetsFlutterBindingdoes) to look for some hook to override the default resolution.tvolkert commentedon Nov 13, 2017
Actually it looks like:
AutomatedTestWidgetsFlutterBindingautomatically pick up the desired resolution.LiveTestWidgetsFlutterBindingto provide a hook whereby the developer could specify the fixed resolution in which they want to run. Otherwise, even though the real test was run in a resolution specified by the developer, aflutter runinvocation of that test would yield a different resolution.Hixie commentedon Nov 13, 2017
Just wrap the widget under test in a SizedBox (contained in a Center) with the given size. Optionally add a MediaQuery in there too if that matters.
robertoscaramuzzi commentedon Nov 14, 2017
Thanks, Hixie. That seems to work, but it's entirely non-obvious. It would be good to provide a better API.
Hixie commentedon Nov 14, 2017
We should definitely document it, maybe provide some arguments to pumpWidget to do it for you.
alanrussian commentedon Dec 8, 2017
IIRC the current default size isn't documented anywhere. That might be helpful to document too.
alanrussian commentedon May 21, 2018
Not sure how much this is related but it would be useful if we could take full-page screenshots of entire widgets for screenshot tests. For example: if you have a
ListViewthat extends beyond the default viewport, the screenshot would capture the entireListView. Also, if you have a widget less than the default viewport, it could capture an image that's just that widget's size.tvolkert commentedon May 21, 2018
At least the second use case is possible by inserting a
RepaintBoundaryin the hierarchy where you want to cap the screenshot.Hixie commentedon May 21, 2018
ListViews don't go beyond the viewport. That's sort of the entire point of a ListView. :-) They don't even reify the widgets that aren't visible.
You could always create a RepaintBoundary around a SizedBox that is the size you want, though, and put the ListView inside that.
alanrussian commentedon May 21, 2018
Thanks, Todd. That's exactly what I was looking for.
Ian, I guess maybe what I'm asking for just not possible to implement with the design of
ListViews. I'm basically asking for what you describe in your second paragraph but for it to somehow know how large the screen is. Maybe we could create our own implementation by scrolling the screen down until it won't scroll anymore and determining the height. cc @johnfesatvolkert commentedon Jun 12, 2018
@Hixie, @paolosoares reports that he'd like to not just change the size of the produced image -- he'd like to change the constraints so that the widget lays out differently.
15 remaining items
acoutts commentedon Apr 19, 2020
Is there any solution to this? I can't get my widget test to run because of a phantom overflow somewhere.
I tried adjusting MediaQuery and this:
But I can't fix this overflow. Those dimensions are the same as the iphone simulator and it runs fine in that. How can we fix widget test sizing?
jamesderlin commentedon Jul 28, 2020
For simulating screen rotation, it seems that the
SizedBox+MediaQueryapproach might not behave quite like an actual screen rotation on a device. I've observed an actual screen rotation triggeringLayer.attachwithout triggeringLayer.addToScene, but changing the dimensions of aSizedBoxseems to trigger both.markusaksli-nc commentedon Jul 30, 2020
flutter/website#2005 is relevant as well here
juanmendez commentedon Jul 14, 2021
it was just magic when dealing with an app made for a tablet. thank you!
dnfield commentedon Aug 20, 2021
The correct way to do this is to call
setSurfaceSizeon the binding.E.g.
tester.binding.setSurfaceSize(size);github-actions commentedon Sep 3, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.