【问题标题】:Flutter error with ListView.builder(). error: Bottom Overflowed by 279 pixelsListView.builder() 出现颤振错误。错误:底部溢出 279 像素
【发布时间】:2020-11-16 13:59:19
【问题描述】:
class TransactionWidget extends StatelessWidget {
  final List<Transaction> _transaction;

  TransactionWidget(this._transaction);
  @override
  Widget build(BuildContext context) {
    return Container(
        height: 500,
        child: ListView.builder(
          itemBuilder: (ctx, index) {
            return Card(
                child: Row(
              children: <Widget>[
                Container(
                  margin: EdgeInsets.symmetric(horizontal: 15, vertical: 10),
                  child: Text(
                    '\$${_transaction[index].amount.toString()}',
                    style: TextStyle(
                        fontWeight: FontWeight.bold,
                        fontSize: 20,
                        color: Colors.blue),
                  ),
                  decoration: BoxDecoration(
                      border: Border.all(width: 2, color: Colors.lightBlue)),
                  padding: EdgeInsets.all(8),
                ), // amount ICON (Left)
                Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      _transaction[index].title,
                      style:
                          TextStyle(fontWeight: FontWeight.bold, fontSize: 17),
                    ), // Text Title
                    Text(
                      DateFormat('dd-MM-yyyy').format(_transaction[index].date),
                      style: TextStyle(fontSize: 13, color: Colors.grey),
                    ), // Text Date
                  ],
                ) // Text of Title and Date
              ],
            ));
          },
          itemCount: _transaction.length,
        ));
  }
}

我正在构建一个显示用户输入的交易列表的颤振应用程序。以下代码用于构建和显示多个事务,但是每当我打开键盘输入新事务时,就会发生溢出错误。在交易列表上方,我添加了“卡片”小部件,该小部件接受用户输入并添加新交易。 The screenshot of the app

【问题讨论】:

    标签: flutter dart


    【解决方案1】:
    Scaffold(
      resizeToAvoidBottomInset: false, 
      ... 
    )
    

    这将避免在键盘打开时调整大小,从而避免任何溢出

    【讨论】:

      【解决方案2】:

      您在 Container 中使用了固定大小,即“height: 500”,所以不要关心您是否使用 ListView。 如果可以,请尝试删除,因为ListView 将管理大小。

      【讨论】:

        【解决方案3】:

        您可以使用 Expanded 小部件包裹您的列表视图容器,而不是将列表视图容器的高度设置为 500,这将调整列表视图以适应屏幕大小和方向的变化。

        【讨论】:

          猜你喜欢
          • 2020-09-04
          • 2019-11-26
          • 2020-11-13
          • 1970-01-01
          • 1970-01-01
          • 2021-09-05
          • 2021-10-06
          • 2019-03-22
          • 2020-02-04
          相关资源
          最近更新 更多