@@ -181,9 +181,25 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow {
181181 double windowInnerWidth;
182182 double windowInnerHeight;
183183 final html.VisualViewport ? viewport = html.window.visualViewport;
184+
184185 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+ }
187203 } else {
188204 windowInnerWidth = html.window.innerWidth! * devicePixelRatio;
189205 windowInnerHeight = html.window.innerHeight! * devicePixelRatio;
@@ -195,11 +211,15 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow {
195211 }
196212 }
197213
198- void computeOnScreenKeyboardInsets () {
214+ void computeOnScreenKeyboardInsets (bool isEditingOnMobile ) {
199215 double windowInnerHeight;
200216 final html.VisualViewport ? viewport = html.window.visualViewport;
201217 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+ }
203223 } else {
204224 windowInnerHeight = html.window.innerHeight! * devicePixelRatio;
205225 }
0 commit comments