3
votes

I'm still very new to flutter and I'm trying to create a comment list section where the child comment can be nested in the parent comment.

What I did was create a ListView inside a dynamic ListView in this case I used a 3rd party library PagewiseListView for lazy loading. But there was some error in building the List.

 @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: pageWiseBuilder(context, _story.kids ?? [], PAGE_SIZE),
    );
  }

  Widget pageWiseBuilder(BuildContext context, List<int> list, int pageSize) {
    if (list != null && list.length > 0) {
      return PagewiseListView(
        padding: EdgeInsets.all(15.0),
        pageSize: pageSize,
        itemBuilder: this.itemBuilder,
        pageFuture: (pageIndex) =>
            _repository.fetchComments(list, pageIndex * pageSize, pageSize),
      );
    } else {
      return Container();
    }
  }

  Widget itemBuilder(BuildContext context, Comment entry, int index) {
    return Column(
      children: <Widget>[
        ListTile(
          title: Text(entry.by ??= ""),
          subtitle: Html(
            data: unescape.convert(entry.text ??= ""),
            useRichText: true,
            onLinkTap: (url) {
              _launchURL(url);
            },
            showImages: true,
            renderNewlines: true,
          ),
        ),
        Divider(),
        Column(
          mainAxisSize: MainAxisSize.min,
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Expanded(
              child: SizedBox(height: 200.0,
                child: ListView.builder(
                  physics: ClampingScrollPhysics(),
                  shrinkWrap: true,
                  itemCount: 5,
                  itemBuilder: (context, index) {
                    return Padding(
                      padding: EdgeInsets.only(top: 8.0),
                      child: Text('Nested list item $index'),
                    );
                  },
                ),
              ),
            ),
          ],
        ),
      ],
    );
  }

I/flutter ( 885): Another exception was thrown: RenderFlex children have non-zero flex but incoming height constraints are unbounded.

I/flutter ( 885): Another exception was thrown: RenderBox was not laid out: RenderFlex#a1031 relayoutBoundary=up6 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE

I/flutter ( 885): Another exception was thrown: RenderBox was not laid out: RenderFlex#11980 relayoutBoundary=up5 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE

I/flutter ( 885): Another exception was thrown: RenderFlex children have non-zero flex but incoming height constraints are unbounded.

I/flutter ( 885): Another exception was thrown: RenderBox was not laid out: RenderFlex#a33b5 relayoutBoundary=up6 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE

I/flutter ( 885): Another exception was thrown: RenderBox was not laid out: RenderFlex#48c2a relayoutBoundary=up5 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE

I/flutter ( 885): Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#d6726 relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE

I/flutter ( 885): Another exception was thrown: 'package:flutter/src/rendering/sliver_multi_box_adaptor.dart': Failed assertion: line 549 pos 12: 'child.hasSize': is not true.

I/flutter ( 885): Another exception was thrown: NoSuchMethodError: The method '>' was called on null.

I/flutter ( 885): Another exception was thrown: 'package:flutter/src/rendering/sliver_multi_box_adaptor.dart': Failed assertion: line 549 pos 12: 'child.hasSize': is not true.

2
Did you tried to remove the Expanded widget? (inside your column) Was the library working before?Mariano Zorrilla
@MarianoZorrilla Yes, I've tried removing Expanded and SizedBox widget with no success. The list will only work if the Nested ListView removed.madz
Did you tried to use a CustomScrollView with a SliverList? That should allow you to use a ListView inside another one.Mariano Zorrilla
@MarianoZorrilla Yes, I've tried it and it gives the same error.madz

2 Answers

2
votes

Your ListView must be wrapped with a Widget that has at least the height.

  Container(
    height: 100,
    child: ListView(
            scrollDirection: Axis.horizontal,
            children: <Widget>[],
            ),
 ),
0
votes

I think you need to remove any Flexible in your code, It works for me.