Flutter开发HarmonyOS鸿蒙Next应用的时候showModalBottomSheet方法下,用FutureBuilder加载TextFormField组件键盘弹不出来

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

Flutter开发HarmonyOS鸿蒙Next应用的时候showModalBottomSheet方法下,用FutureBuilder加载TextFormField组件键盘弹不出来
``` 【任务描述】 import ‘package:edu_app/bottom_up/TextInputBottomUp.dart’ deferred as TextInputBottomUp;

Future<String?> showTextInputBottomUp({ String title = “内容填写”, String value = “”, PopValidator<String>? validator, String tip = “”, double? height, TextInputType? keyboardType, String label=’’ }) async { return await showBottomUp( builder: (context) => FutureBuilder( future: TextInputBottomUp.loadLibrary(), builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot)=> deferLoadPage(()=> TextInputBottomUp.TextInputBottomUp( title: title, value:value, validator: validator, tip:tip, height: height, keyboardType:keyboardType, label: label, ),snapshot) ) ); }

Future<T?> showBottomUp<T>({ BuildContext context, required WidgetBuilder builder, Color? barrierColor, bool enableDrag = true, bool isDismissible = true }) async{ return await showModalBottomSheet( context: context, builder: builder, isScrollControlled:true, useSafeArea: true, barrierColor: barrierColor, enableDrag:enableDrag, isDismissible: isDismissible ); }

showTextInputBottomUp();

import ‘package:edu_app/boot/BottomUp.dart’; import ‘package:edu_app/boot/Global.dart’; import ‘package:flutter/material.dart’;

class TextInputBottomUp extends StatefulWidget { final String title; final String value; final PopValidator<String>? validator; final String tip; final double? height; final TextInputType? keyboardType; final String label;

const TextInputBottomUp({ required this.title, required this.value, this.validator, required this.tip, required this.height, this.keyboardType, required this.label, super.key });

@override State<TextInputBottomUp> createState() => _TextInputBottomUpState(); }

class _TextInputBottomUpState extends State<TextInputBottomUp> { String value = “”; late double height;

@override void initState() { value = widget.value; height = widget.height ?? (widget.tip.isNotEmpty ? 296 : 264); super.initState(); }

@override Widget build(BuildContext context) { return BottomUp( height: height, appBar: BottomUpAppBar(title: Text(widget.title)), body: ListView( padding: const EdgeInsets.all(8), children: [ if(widget.tip.isNotEmpty) Text(widget.tip,style: const TextStyle(color: Colors.green,fontSize: 12),), if(widget.tip.isNotEmpty) const SizedBox(height: 8,), if(widget.label.isNotEmpty) Text.rich(TextSpan(children: [ Global.requiredTextSpan, TextSpan(text:widget.label) ])), if(widget.label.isNotEmpty) const SizedBox(height: 4,), TextFormField( initialValue: value, keyboardType: widget.keyboardType, decoration: InputDecoration( border: InputBorder.none, filled: true, fillColor: Colors.grey.shade100, isDense: true, hintText: “请填写内容”, ), // 校验用户名 minLines: 8, maxLines: 8, onChanged: (v){ value = v; }, ) ], ), persistentFooterButtons: [ ElevatedButton( style: ButtonStyle(backgroundColor: MaterialStateProperty.all(Colors.grey)), onPressed: () async { Navigator.of(context).pop(); }, child: const Text(“关闭”), ), ElevatedButton( onPressed: () async { if(value.isEmpty){ showRespFail(“请先填写内容”); return; }

        if(widget.validator != null){
          var yes = await widget.validator!(value);
          if(yes != null && !yes){
            return;
          }
        }
        Navigator.of(context).pop(value);
      },
      child: const Text("确定"),
    )
  ],
);

} }

【解决方案】

【任务来源】

2 回复

伙伴你好,该问题麻烦您关闭issue另外提交ir单跟踪处理哈 https://issuereporter.developer.huawei.com/

在Flutter开发HarmonyOS鸿蒙Next应用时,遇到showModalBottomSheet方法下使用FutureBuilder加载TextFormField组件时键盘无法弹出的问题,可能是由于底层系统或Flutter引擎对模态底部表单(Modal Bottom Sheet)和键盘弹出逻辑的处理方式导致。

一种可能的解决方向是检查showModalBottomSheet的上下文(context)是否正确传递,确保它包含了必要的键盘焦点管理逻辑。同时,确认TextFormField是否已被正确包裹在FocusScopeFocus节点中,以便系统能正确识别并响应键盘输入需求。

此外,尝试调整FutureBuilder的状态管理逻辑,确保在数据加载完成前不阻塞UI更新,或者在数据加载完成后再动态添加TextFormField,以避免加载过程中的状态冲突。

最后,考虑到HarmonyOS与Android和iOS的差异,建议查阅最新的Flutter与HarmonyOS集成文档,确认是否有特定于鸿蒙系统的注意事项或限制。

如果问题依旧没法解决请联系官网客服,官网地址是:https://www.itying.com/category-93-b0.html

回到顶部