首页 > 解决方案 > Flutter TextFormField 在键盘出现时隐藏

问题描述

我是颤振的新手,我有一个问题。当我单击 textformField 时,这个消失了

我将容器放入红色,但通常它是透明的

我放了一个堆栈,然后在后台扩展了 GoogleMap。为了产生研究效果,我在 textformfield 上放置了一个叠加层,我将使用特定的过滤器按钮而不是黄色和绿色。

问题是,当我单击 textformfield 时,它会从屏幕上消失。我尝试使用 SingleChildScrollView、ListView,但我仍然有错误,特别是因为 GoogleMap 占用了所有空间所有内容都包含在 Scaffold 中

你能帮我吗,在哪里给我一个解决方案?我附上下面的代码

亲切地

在此处输入图像描述

在此处输入图像描述

return Stack( children: [ /// GoogleMap Column( children: [ Expanded( child: GoogleMap(initialCameraPosition: _kInitialPosition), ), ], ),

    /// Search Bar And Filter
    Positioned.fill(
      bottom: _searchBarContainer,
      child: SafeArea(
        child: Container(
          color: Colors.red,
          child: Padding(
            padding: const EdgeInsets.only(left: 8.0, right: 8.0),
            child: Row(
              children: [
                /// Search Bar
                Expanded(
                  child: TextFormField(
                    decoration: DesignWidget.inputDecorationTexFieldMap(
                        _searchBarMap, Icons.search),
                  ),
                ),

                /// Filter
                Container(
                  width: _filterContainer,
                  color: Colors.green,
                  child: Row(
                    children: [
                      Container(
                        color: Colors.yellow,
                        width: _filterContainer / 2,
                      ),
                      Container(
                        color: Colors.green,
                        width: _filterContainer / 2,
                      )
                    ],
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    ),
  ],
);

标签: fluttergoogle-mapsdartsinglechildscrollview

解决方案


我认为在使用 textFormField 之前,您必须定义一个键或控制器.....当您没有定义控制器实例并在 textFormField 控制器内部使用该控制器时,就会发生这种情况。


推荐阅读