【问题标题】:A RenderFlex overflowed by 45 pixels on the bottom?底部溢出 45 个像素的 RenderFlex?
【发布时间】:2021-08-04 15:17:46
【问题描述】:

我遇到了 Flutter (Dart) RenderFlex 溢出像素的问题。渲染库异常。

当键盘打开时,它会在下面显示消息:

一个 RenderFlex 在底部溢出了 45enter image description here 个像素。

如果您有任何机会需要完整的日志来帮助我,请点击此处:

  @override
  Widget build(BuildContext context) {
    return Card(
      elevation: 5,
      child: Container(
        margin: EdgeInsets.all(10),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.end,
          children: [
            TextField(
              decoration: InputDecoration(labelText: 'Title'),
              controller: _titleController,
              onSubmitted: (_) => _submitData,
              // onChanged: (val) {
              //   titleInput = val;
              // },
            ),
            TextField(
              decoration: InputDecoration(labelText: 'Amount'),
              controller: _amountController,
              keyboardType: TextInputType.number,
              onSubmitted: (_) => _submitData,
              // onChanged: (val) => amountInput = val,
            ),
            Container(
              height: 70,
              child: Row(
                children: [
                  Expanded(
                    child: Text(_selectedDate == null
                        ? "No Date Choosen!"
                        : 'Picked Date: ${DateFormat.yMd().format(_selectedDate)}'),
                  ),
                  TextButton(
                      onPressed: _presentDatePicker,
                      child: Text(
                        'Choose the Date!',
                        style: TextStyle(
                            color: Theme.of(context).primaryColor,
                            fontWeight: FontWeight.bold),
                      ))
                ],
              ),
            ),
            ElevatedButton(
              onPressed: _submitData,
              // () {
              // print(titleInput);
              // print(amountInput);
              // print(titleController.text);
              // print(amountController.text);
              //   addTx(
              //       titleController.text, double.parse(amountController.text));
              // },
              child: Text(
                'Add Transaction',
                style: TextStyle(color: Colors.white),
              ),
              style: ButtonStyle(
                  foregroundColor: MaterialStateProperty.all(Colors.purple)),
            )
          ],
        ),
      ),
    );
  }
}

【问题讨论】:

  • 我建议的最简单的方法是用 SingleChildScrollView 包装你的列
  • 我认为 OP 需要它是可滚动的,不是吗?

标签: flutter flutter-layout


【解决方案1】:

您可以将 SingleChildScrollView 添加到 Card 小部件。这将有助于滚动您的页面,并且像素错误将消失。

【讨论】:

【解决方案2】:

您可以通过 SinglechildScrollView 包装卡片小部件,这将使其可滚动,因此为键盘提供足够的尺寸,也可以在 Scaffold 中制作它

resizeToAvoidBottomInset: true,

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-13
    • 2021-08-27
    • 2019-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-30
    • 2020-12-29
    相关资源
    最近更新 更多