From 66c6081e0cd186f51d5089037c3f4ea64294aecc Mon Sep 17 00:00:00 2001 From: wwyang <137208408@qq.com> Date: Thu, 31 Oct 2024 20:07:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0web=E9=97=AA=E5=B1=8F?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=96=B9=E6=A1=88FAQ?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...43\345\206\263\346\226\271\346\241\210.md" | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 "ohos/docs/08_FAQ/web\351\227\252\345\261\217\350\247\243\345\206\263\346\226\271\346\241\210.md" diff --git "a/ohos/docs/08_FAQ/web\351\227\252\345\261\217\350\247\243\345\206\263\346\226\271\346\241\210.md" "b/ohos/docs/08_FAQ/web\351\227\252\345\261\217\350\247\243\345\206\263\346\226\271\346\241\210.md" new file mode 100644 index 00000000..2eb53012 --- /dev/null +++ "b/ohos/docs/08_FAQ/web\351\227\252\345\261\217\350\247\243\345\206\263\346\226\271\346\241\210.md" @@ -0,0 +1,68 @@ +#### Web页面弹出键盘/收起键盘 闪屏问题解决方案: + +参考资料:https://www.modb.pro/db/638000 + +1,在最外面包一层`MediaQuery` + +2,自定义`useInheritedMediaQuery`属性为true + +3,使用`SafeArea`包裹web区域 + + + +```js +class MyApp extends StatelessWidget { + const MyApp({super.key}); + + @override + Widget build(BuildContext context) { + return MediaQuery( + data: MediaQueryData.fromWindow(WidgetsBinding.instance.window), + child: MaterialApp( + title: 'Flutter Demo', + useInheritedMediaQuery: true, + theme: ThemeData( + primarySwatch: Colors.blue, + ), + home: const WebPage(title: 'Flutter Demo Home Page'), + )); + } +} + +class WebPage extends StatefulWidget { + const WebPage({super.key, required this.title}); + + final String title; + + @override + State createState() => _WebPageState(); +} + +class _WebPageState extends State { + late final WebViewController controller; + + @override + void initState() { + super.initState(); + controller = WebViewController.fromPlatformCreationParams( + const PlatformWebViewControllerCreationParams(), + ); + controller.loadRequest(Uri.parse("https://www.baidu.cn/")); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + resizeToAvoidBottomInset: false, + body: SafeArea( + child: WebViewWidget( + controller: controller, + ), + ), + ); + } +} + + +``` + -- Gitee