首页 > 解决方案 > RenderBox 未布置:RenderRepaintBoundary

问题描述

我在使用 listview builder 时遇到错误,不知道如何解决。如果我删除 Listview 构建器代码,那么它不会给出错误。

这是代码。

  Widget build(BuildContext context) {
   
    return Theme(
      isMaterialAppTheme: true,
      data: ThemeData(
      ),

     child:Scaffold(
      backgroundColor: _dark ? null : Colors.grey.shade200,
      key: _scaffoldKey,
      appBar: myAppBar(),
      endDrawer: myDrawer(),

      body: Stack(
        children: <Widget>[
      
      SingleChildScrollView(
        child: Stack(
          children: <Widget>[
            
            Container(
              margin: EdgeInsets.fromLTRB(16.0, 10.0, 16.0, 16.0),
              child: Column(
                children: <Widget>[
                  Stack(
                    children: <Widget>[
                      Container(
                            decoration: BoxDecoration(
                            color:Colors.grey,
                          //  color: Colors.orange,
                                    borderRadius: BorderRadius.only(
                                        bottomLeft: Radius.circular(4.0),
                                        bottomRight: Radius.circular(4.0))),
                            padding: EdgeInsets.symmetric(horizontal:16.0, vertical: 15.0),
                            width: double.infinity,
                            child: Text("Booking Details",
                              textAlign: TextAlign.center,
                              style: TextStyle(
                              fontSize: 18.0,
              //                fontWeight: FontWeight.bold,
                              color: Colors.white,
                              letterSpacing: 3,
                              wordSpacing: 3
                       ),),
                            ),
              
                     ],
                  ),
                  SizedBox(height: 20.0),
                    Container(
      child: new ListView.builder(
          itemCount:  lists.length,
          itemBuilder: (BuildContext context, int i) {
            return Card(
              margin:
              const EdgeInsets.fromLTRB(10.0, 15.0, 10.0, 0.0),
              child: new ExpansionPanelList(
                expansionCallback: (int index, bool status) {
                  setState(() {
                    _selectedIndex= index;
                    _selectedIndex = _selectedIndex == i ? null : i;
                  });
                },
                children: [
                  new ExpansionPanel(
                      isExpanded: _selectedIndex == i,
                      headerBuilder: (BuildContext context,
                          bool isExpanded) =>
                      new Container(
                          padding:
                          const EdgeInsets.only(left: 15.0),
                          alignment: Alignment.centerLeft,
                          child: new Text(
                            'list-$i',
                          )),
                      body: new Container(child: new Text('content-$i'),),),
                ],
              ),
            );
          }),
    ),    

我该如何解决这个问题?

标签: flutter

解决方案


您可以尝试为保存您的列表视图的容器设置高度

 Container(
    height: 200.0, //for example
    child: ListView.builder(
      //your code
    )
 )

推荐阅读