【问题标题】:How to move child of column above keyboard instead of whole column?如何在键盘上方移动列子而不是整个列?
【发布时间】:2021-10-06 06:19:59
【问题描述】:

我尝试使用 singleChildScrollView 使用属性 reverse: true 将整个屏幕移动到键盘上方。但我只想将底部容器移动到键盘上方,就像在 google keep notes 应用程序中一样。

编辑:-

编辑 2:- 这是我想要在键盘上方的容器。它是列的一部分。

Screenshot of my App

这是我的容器代码。

  Container controlButtons() {
    return Container(
      margin: const EdgeInsets.all(20),
      decoration: BoxDecoration(
        border:
            Border.all(color: Theme.of(context).textSelectionColor, width: 0.3),
        borderRadius: BorderRadius.circular(20),
      ),
      child: Padding(
        padding: const EdgeInsets.all(12.0),
        child: Row(
          //row of back and next button
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            InkWell(
              onTap: controlBack,
              child: Row(
                children: [
                  const Icon(Icons.arrow_back_ios),
                  (index != 0) ? const Text('Back') : const Text('Cancel'),
                ],
              ),
            ),
            InkWell(
              onTap: controlNext,
              child: Row(
                children: [
                  (index != 3) ? const Text('Next') : const Text('Save'),
                  const Icon(Icons.arrow_forward_ios),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }```

[![My App Screen Screenshot][2]][2]


 


【问题讨论】:

  • 很抱歉,您的陈述仍然无法理解。请详细说明。如果事情变得可以理解,我一定会帮助你。
  • @ShrutiRamnandanSharma 我添加了一个记事本屏幕截图,其中容器位于键盘上方。我想在我的容器上实现相同的功能。

标签: android flutter flutter-layout


【解决方案1】:

这里推荐的方法是使用Expanded 小部件来“拉伸”Keep 中的注释,以便按钮栏与末尾对齐。

return Column(
  children: [
    Expanded(
      child: MyNoteEnteringField(),
    ),
    MyButtonBarAboveKeyboard(),
  ],
);

这应该将具有设定高度的按钮栏与页面末尾对齐:键盘关闭时,它与屏幕底部对齐,键盘打开时,它向上移动到键盘的正上方。

【讨论】:

  • 我的容器是列的一部分。这是最后一个孩子。我只是想让这个键盘出现在键盘上方,而其他人保持不变。
  • 那么您还应该能够在它们之间放置一个“空”Expanded 小部件,以确保您的容器一直向下推
【解决方案2】:

使用Expanded Widget,使底栏对齐到末尾。

children: [
    Expanded(
      child: 'Do stuff here'
    ),
    (.....
  ],

【讨论】:

  • 嘿,兄弟,我将我的文本字段展开并删除了我分配给包含列的容器的高度,它起作用了。谢谢老兄。
  • 太棒了!这很好。
猜你喜欢
  • 2017-08-23
  • 2020-06-03
  • 1970-01-01
  • 1970-01-01
  • 2019-06-12
  • 1970-01-01
  • 2017-01-05
  • 2017-07-22
  • 1970-01-01
相关资源
最近更新 更多