【问题标题】:how to resize or move all the child widgets of stack when one of it's grandchild is input TextField in flutter当其中一个孙子小部件在颤动中输入TextField时,如何调整堆栈的所有子小部件的大小或移动它
【发布时间】:2020-11-01 00:23:02
【问题描述】:

我在堆栈小部件中定位(使用对齐)两个子小部件,其中一个包含表单 TextField 以获取输入。当我点击输入数据时,只有它的父小部件在键盘上向上移动,如下图所示。 从键盘输入数据时,有什么方法可以移动/调整堆栈的子小部件的大小。

源代码:

return Scaffold(
      body: Stack(
          children: <Widget>[
          Container(
            padding: EdgeInsets.all(10),
            decoration: BoxDecoration(
                image: DecorationImage(
                    image: AssetImage('assets/images/playingboard2.jpg'),
                    fit: BoxFit.cover)),
            child: null,
          ),
          _buildSelfPlayer(), // Returns the widget with form input and other widgets
          _buildBank(), // top center, shows two pictures of bank
        ],
      ),
    );
 

【问题讨论】:

  • 您是否尝试将Stack 包裹在具有垂直滚动方向的SingleChildScrollView 中?
  • 是的,我试过了,然后所有的小部件都失去了对齐并在顶部中心堆积。

标签: flutter flutter-layout


【解决方案1】:

我没有看到其他解决方法,同时还使用了Stack 小部件。

因此,我建议您使用包裹在SingleChildScrollView 中的Column 小部件。我试过了,它按预期工作。其他孩子也跟着TextField向上移动,所以要保持他们之间的距离,不要重叠。

对于背景图片,您可以将Scaffold 包裹在Container 中,在列装饰中使用该图片并将脚手架的backgroundColor 制作成Colors.transparent

【讨论】:

    猜你喜欢
    • 2012-04-14
    • 2021-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-08
    • 2019-07-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多