HarmonyOS 鸿蒙Next flutter鸿蒙化 输入法相关问题

发布于 1周前 作者 zlyuanteng 来自 鸿蒙OS

HarmonyOS 鸿蒙Next flutter鸿蒙化 输入法相关问题

软键盘弹起和收入事件反映到键盘高度的数据不正确

StatefulWidget页面中,添加WidgetsBindingObserver监听。

在didChangeMetrics方法中,通过  final bottomInset = MediaQuery.of(context).viewInsets.bottom;

监听软键盘高度变化,当键盘弹起时,此数值依然为0,多次测试,结果不变。

2 回复

可参考demo,如下可实现键盘弹起时候显示实际高度,键盘收起时候高度为0


import 'package:flutter/material.dart';
void main() {
  runApp(const MyApp());
}
class MyApp extends StatelessWidget {
  const MyApp({super.key});
// This widget is the root of your application.
  [@override](/user/override)
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}
class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});
  [@override](/user/override)
  State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
  int _bottomInset = 1;
  bool _isKeyboardVisible = false;
  [@override](/user/override)
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
  }
  [@override](/user/override)
  void dispose() {
    super.dispose();
    WidgetsBinding.instance.removeObserver(this);
  }
  [@override](/user/override)
  void didChangeMetrics() {
    super.didChangeMetrics();
  }
  [@override](/user/override)
  Widget build(BuildContext context) {
    final bottomInset = MediaQuery.of(context).viewInsets.bottom;
    final isKeyboardVisible = bottomInset > 0.0;
    print("键盘高度${bottomInset}");
    setState(() {
      _bottomInset = bottomInset.toInt();
    });
    if (isKeyboardVisible != _isKeyboardVisible) {
      setState(() {
        _isKeyboardVisible = isKeyboardVisible;
      });
    }
    return Scaffold(
      appBar: AppBar(
// TRY THIS: Try changing the color here to a specific color (to
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
// change color while the other colors stay the same.
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
        title: Text("测试"),
      ),
      body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
        child: Container(
          width: 200,
          height: 40,
          child: Row(
            children: [
              Text("键盘高度${_bottomInset}"),
              Expanded(
                child: TextField(),
              )
            ],
          ),
        ),
      ),
    );
  }
}
 

针对“HarmonyOS 鸿蒙Next flutter鸿蒙化 输入法相关问题”,作为IT专家,我认为可以从以下几个方面进行解析:

  1. HarmonyOS 鸿蒙Next:是华为推出的面向未来的应用开发框架,依托鸿蒙生态系统,支持多设备协同和物联网场景。
  2. Flutter鸿蒙化:指的是将Flutter应用或技术融入鸿蒙生态系统中,利用鸿蒙的分布式能力、软硬件协同优化等优势。但HarmonyOS 鸿蒙Next本身已提供强大的开发框架,开发者可直接基于其开发,无需额外“Flutter鸿蒙化”。
  3. 输入法相关问题:近期有用户反馈,在使用微博鸿蒙客户端时遇到输入法不正常的问题,如打字丢字等。初步判断是由NEXT鸿蒙系统缺陷引起,华为已在积极排期修复。

如果用户在鸿蒙Next系统或Flutter鸿蒙化过程中遇到输入法相关问题,建议检查输入法版本是否与系统兼容,并尝试重启设备或重新安装输入法。若问题依旧存在,请直接联系官网客服,官网地址是:https://www.itying.com/category-93-b0.html

回到顶部