@@ -181,9 +181,25 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow {
181
181
double windowInnerWidth;
182
182
double windowInnerHeight;
183
183
final html.VisualViewport ? viewport = html.window.visualViewport;
184
+
184
185
if (viewport != null ) {
185
- windowInnerWidth = viewport.width! .toDouble () * devicePixelRatio;
186
- windowInnerHeight = viewport.height! .toDouble () * devicePixelRatio;
186
+ if (operatingSystem == OperatingSystem .iOs) {
187
+ /// Chrome on iOS reports incorrect viewport.height when app
188
+ /// starts in portrait orientation and the phone is rotated to
189
+ /// landscape.
190
+ ///
191
+ /// We instead use documentElement clientWidth/Height to read
192
+ /// accurate physical size. VisualViewport api is only used during
193
+ /// text editing to make sure inset is correctly reported to
194
+ /// framework.
195
+ final double docWidth = html.document.documentElement! .clientWidth.toDouble ();
196
+ final double docHeight = html.document.documentElement! .clientHeight.toDouble ();
197
+ windowInnerWidth = docWidth * devicePixelRatio;
198
+ windowInnerHeight = docHeight * devicePixelRatio;
199
+ } else {
200
+ windowInnerWidth = viewport.width! .toDouble () * devicePixelRatio;
201
+ windowInnerHeight = viewport.height! .toDouble () * devicePixelRatio;
202
+ }
187
203
} else {
188
204
windowInnerWidth = html.window.innerWidth! * devicePixelRatio;
189
205
windowInnerHeight = html.window.innerHeight! * devicePixelRatio;
@@ -195,11 +211,15 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow {
195
211
}
196
212
}
197
213
198
- void computeOnScreenKeyboardInsets () {
214
+ void computeOnScreenKeyboardInsets (bool isEditingOnMobile ) {
199
215
double windowInnerHeight;
200
216
final html.VisualViewport ? viewport = html.window.visualViewport;
201
217
if (viewport != null ) {
202
- windowInnerHeight = viewport.height! .toDouble () * devicePixelRatio;
218
+ if (operatingSystem == OperatingSystem .iOs && ! isEditingOnMobile) {
219
+ windowInnerHeight = html.document.documentElement! .clientHeight * devicePixelRatio;
220
+ } else {
221
+ windowInnerHeight = viewport.height! .toDouble () * devicePixelRatio;
222
+ }
203
223
} else {
204
224
windowInnerHeight = html.window.innerHeight! * devicePixelRatio;
205
225
}
0 commit comments