0

I'm getting the error stated that Incorrect use of ParentDataWidget while using ListView widget into Stack widget and using ListView.builder widget into ListView widget. (I need a scrollable page that contains ListView and GridView)

It works fine in the emulator (not working in the real device) but in a log, I'm getting error.

I'm posting both screenshots and code here.

Please help!

Screenshot of emulator

enter image description here

Screenshot of a real device

enter image description here

Check the below code

@override
  Widget build(BuildContext context) {
    return Scaffold(
        resizeToAvoidBottomInset: false,
        appBar: buildAppBar(),
        body: Stack(
          children: [
            buildBody()
          ],
        )
    );
  }


Widget buildBody() {
    return Container(
        padding: EdgeInsets.all(15.0),
        child: Expanded(
            child: ListView(
              shrinkWrap: true,
              children: [
                buildTitleSection(),
                buildSearchSection(),
                buildFilterSortSection(),
                buildListView(),
                buildGridView()
              ],
            ),
        )
    );
  }


Widget buildListView() {
    return Visibility(
      visible: isListVisible,
      child: Expanded(
          child: SingleChildScrollView(
              child: ConstrainedBox(
                  constraints: BoxConstraints(),
                  child: ListView.builder(
                    itemCount: items.length,
                    shrinkWrap: true,
                    physics: PageScrollPhysics(),
                    scrollDirection: Axis.vertical,
                    itemBuilder: (context, index) =>
                        buildRowItemsList(context, index),
                  )))),
    );
  }


Widget buildGridView() {
    var screenWidth = MediaQuery
        .of(context)
        .size
        .width;
    var screenHeight = MediaQuery
        .of(context)
        .size
        .height;

    return Builder(builder: (BuildContext context) {
      return Visibility(
        visible: isGridVisible,
        child: Expanded(
          child: GridView.count(
              crossAxisCount: 2,
              childAspectRatio: screenWidth / (screenHeight * 0.7),
              scrollDirection: Axis.vertical,
              physics: PageScrollPhysics(),
              shrinkWrap: true,
              children: List.generate(items.length, (index) {
                return buildRowItemsGrid(context, index);
              })),
        ),
      );
    });
  }

0 Answers0