ListView.Builder中的ListView.Builder不起作用(嵌套的Listviews)

时间:2018-08-27 08:38:45

标签: listview dart flutter flutter-layout

我正在尝试使用AlertDialog来创建ShowDialog,该AlertDialog显示嵌套的ListView:

  showDialog(
    context: context,
    builder: (BuildContext context) {
      return new AlertDialog(
        contentPadding: EdgeInsets.all(0.0),
        content: new Container(
          decoration: BoxDecoration(
            borderRadius: new BorderRadius.circular(40.0),
          ),
          height: 300.0,
          width: 300.0,
          child: new ListView.builder(
              shrinkWrap: true,
              itemCount: filteredKits == null ? 0 : filteredKits.length,
              itemBuilder: (BuildContext context, int index) =>
                  new StickyHeader(
                      header: new Container(
                        width: 300.0,
                        height: 30.0,
                        color: Colors.grey[700],
                        child: Text(
                          kitTypes[index],
                          style: TextStyle(
                              color: Colors.white,
                              fontWeight: FontWeight.w600,
                              fontSize: 15.0),
                        ),
                        padding: EdgeInsets.all(12.0),
                      ),
                      content: SizedBox(
                        height: 80.0,
                        width: 300.0,
                        child: getBrands(
                            kitTypes[index], filteredKits, context), // Function that returns Other ListView.Builder()
                      ))),
        ),
      );
    },
  );

功能:

  getBrands(String kitType, List<Kits> filteredkits, context) {
    var brandlist = filteredkits
        .where((kit) => kit.type == kitType)
        .map((kit) => kit.brand)
        .toList();

    var brandfilter = brandlist.toSet().toList();

    return new ListView.builder(
      shrinkWrap: true,
      itemCount: brandfilter == null ? 0 : brandfilter.length,
      itemBuilder: (BuildContext context, int index) =>
          new Text(brandfilter[index]),
    );
  }

现在可以正常工作,但前提是我将SizeBox放在第二个列表上并且结果不好,因为我希望ListView占据所有空间

静态大小以及嵌套列表中的更多参数显示错误

enter image description here

0 个答案:

没有答案