0

I tried to use nested Listview builder the data can be retrieved but it doesn't appear in the ui, I'm confused I've been looking for it but still haven't found the right solution, this my code:

  Widget _buildViewDataReport(BuildContext context, List<GetReport>listReport){
    return ListView.builder(
            itemCount: listReport.length,
            itemBuilder: (context, index){
              return Container(
                width: double.infinity,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: <Widget>[
                    _getHeader(listReport[index].header),
                    _buildWidgetSizedBox(20),
                    _getDataBody(listReport[index].data),
                  ],
                ),
              );
            }
    );
  }

  Widget _getHeader(List<Header>listHeader){
    return Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.start,
      children: <Widget>[
        Text('INI HEADER TIDAK MASUK LISTVIEW.BUILDER'),
        ListView.builder(
            shrinkWrap: true,
            scrollDirection: Axis.vertical,
            physics: NeverScrollableScrollPhysics(),
            itemCount: listHeader.length,
            itemBuilder: (context, index){
              return Expanded(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Text('${listHeader[index].label} : ${listHeader[index].value}')
                  ],
                ),
              );
            }
        ),
      ],
    );
  }

1 Answer 1

2

Use CustomScrollView and SliverList instead of ListView. Here's an example:

return CustomScrollView(
  slivers: [
    SliverList(
      delegate: SliverChildBuilderDelegate(
        (context, index) => Text('first list, $index'),
        childCount: 10,
      ),
    ),
    SliverList(
      delegate: SliverChildBuilderDelegate(
        (context, index) => Text('second list, $index'),
        childCount: 10,
      ),
    )
  ],
);
Sign up to request clarification or add additional context in comments.

5 Comments

is not working, The argument type 'Text Function(dynamic, dynamic)' can't be assigned to the parameter type 'List<Widget>'.
Can you paste the code you've written and got the error? @farhan
wait, i have one question for you, so, if listview.builder is inside that listview.builder the data won't show up?
Widget _buildViewDataReport(BuildContext context, List<GetReport>listReport){ return ListView.builder( itemCount: listReport.length, itemBuilder: (context, index){ return ListView( children: <Widget>[ _getHeader(context, listReport[index].header), // _buildWidgetSizedBox(20), // _getDataBody(context, listReport[index].data), ], ); } ); }
Widget _getHeader(BuildContext context, List<Header> listHeader){ return CustomScrollView( slivers: [ SliverList( delegate: SliverChildBuilderDelegate( (context, index) => Text('first list, ${listHeader[index].label}'), childCount: 10, ), ), ], ); }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.