【问题标题】:TextformFiled Under the Keyboard when parrent widget is Stack父小部件卡住时键盘下的 TextformField
【发布时间】:2020-07-23 06:08:32
【问题描述】:

我使用 Stack 小部件作为父小部件。在堆栈小部件数组中,第一个小部件是谷歌地图,第二个小部件是 TextFormField,我需要在屏幕下方设置搜索栏,所以我使用定位小部件并在下面设置

          Scaffold(
  extendBodyBehindAppBar: true,
  resizeToAvoidBottomInset: false,
  drawer: Drawer(),
  appBar: CommonWidgets.appbar(true),
  body: Stack(
    children: <Widget>[
      Container(
          child: GoogleMap(
              mapType: MapType.terrain,
              myLocationEnabled: true,
              compassEnabled: true,
              tiltGesturesEnabled: true,
              padding: EdgeInsets.only(
                  top: MediaQuery.of(context).size.height / 5),
              // markers: Set.from(model.allmarkers),
              initialCameraPosition: _kGooglePlex,
              onMapCreated: (GoogleMapController controller) {
                //     model.mapController.complete(controller);
              })),
      Positioned(
          bottom: 30,
          left: 40,
          right: 40,
          child: TextFormField(
              controller: searchController,
              keyboardType: TextInputType.emailAddress,
              decoration: InputDecoration(
                  hintText: "Please enter your ",
                  border: InputBorder.none,
                  fillColor: Colors.amber,
                  filled: true)))
    ],
  ),
);

现在当我使用键盘输入时,我的搜索栏不会出现在软键盘上方。我认为正如我在定位小部件中设置的那样,它正在修复搜索栏并且不移动它。如何解决这个问题呢。我不能使用除 Stack 之外的任何其他小部件,因为它是一个地图屏幕,所有内容都需要显示在地图上方。

【问题讨论】:

    标签: google-maps flutter keyboard


    【解决方案1】:

    你需要把ScaffoldresizeToAvoidBottomInset改成true

    resizeToAvoidBottomInset: true,
    

    【讨论】:

    • 你是对的,但它不起作用,仍然,小部件在键盘下
    • 你的意思是TextFormField 还在键盘下面吗?
    • 奇怪。我只尝试了一次更改Image 小部件而不是地图,并且效果很好。 TextFormField 与键盘一起出现。
    • 只需将您的图像替换为具有完整尺寸和屏幕宽度的容器。它应该是堆栈的第一个元素。即 Container( height: MediaQuery.of(context).size.height, color: Colors.green, width: MediaQuery.of(context).size.width, )
    • 已经有完整尺寸的Image 小部件,但按照您的建议尝试了完整尺寸的Container。并且仍然对我有用。 TextFormField 与键盘一起向上移动。不知道为什么它对我们俩都有不同的行为。
    猜你喜欢
    • 2021-10-11
    • 2020-05-07
    • 1970-01-01
    • 1970-01-01
    • 2021-02-06
    • 1970-01-01
    • 2020-04-28
    • 1970-01-01
    • 2021-08-01
    相关资源
    最近更新 更多