列表视图小部件不显示在我的屏幕上,不能正常工作(在Flutter中)。

问题描述 投票:0回答:1

我想在我的应用程序中有一个ListView,但当我运行它时,我得到一个错误,它不显示(我的自定义部件也不显示)。

Exception caught by rendering library ═════════════════════════════════
RenderBox was not laid out: RenderRepaintBoundary#2aa9b relayoutBoundary=up5 NEEDS-PAINT
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1687 pos 12: 'hasSize'
The relevant error-causing widget was
Column

当我删除该列时,我得到了同样的错误,但相关的错误导致的widget是ListView.Does someone know how to fix it? (我是新来的flutter,我不知道事情到底应该如何工作)。

这是我的代码。(我从flutter docs中提取了ListView的代码。我将改变它,当它会工作)

class DashboardPage extends StatefulWidget {
  @override
  _DashboardPageState createState() => _DashboardPageState();
}

class _DashboardPageState extends State<DashboardPage> {
  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Column(
        children: <Widget>[
          CustomAppBar('Dashboard'),
          ListView(
            padding: const EdgeInsets.all(8),
            children: <Widget>[
              Container(
                height: 50,
                color: Colors.amber[600],
                child: const Center(child: Text('Entry A')),
              ),
              Container(
                height: 50,
                color: Colors.amber[500],
                child: const Center(child: Text('Entry B')),
              ),
              Container(
                height: 50,
                color: Colors.amber[100],
                child: const Center(child: Text('Entry C')),
              ),
            ],
          ),
        ],
      ),
    );
  }
}

CustomAppBar是我做的一个自定义小部件,它在没有ListView的情况下完全可以正常工作。

编辑:截图。我在模拟器上看到的截图:

编辑:我的自定义小组件的代码。

class CustomAppBar extends StatelessWidget {

  CustomAppBar(this.title);

  String title = '';

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: MediaQuery.of(context).size.height * 0.30,
      width: double.infinity,
      child: Container(
        decoration: BoxDecoration(
          borderRadius: BorderRadius.vertical(
            bottom: Radius.elliptical(MediaQuery.of(context).size.width, 60.0)
          ),
          gradient: LinearGradient(
            begin: Alignment.topCenter,
            end: Alignment.bottomCenter,
            colors: [const Color(0XFF3632EA), const Color(0XFF2A27C1)]
          ),
        ),
        child: Container(
          alignment: Alignment.bottomLeft,
          padding: EdgeInsets.only(bottom: 50.0, left: 30.0, right: 30.0),
          child: Text(
            title,
            style: Theme.of(context).textTheme.headline,
          ),
        ),
      ),
    );
  }
}
listview flutter flutter-layout
1个回答
0
投票

将listView的shrinkWrap设置为true.它将解决你的问题。

 ListView(
              shrinkWrap: true,
              padding: const EdgeInsets.all(8),
© www.soinside.com 2019 - 2024. All rights reserved.