不正确使用ParentDataWidget Flutter

时间:2020-08-20 07:31:13

标签: android flutter dart layout cross-platform

我收到错误消息,指出在将ListView小部件用于Stack小部件和在ListView小部件中使用ListView.builder小部件时,不正确使用ParentDataWidget 。 (我需要一个包含ListView和GridView的可滚动页面)

它在仿真器中可以正常工作(在实际设备中不起作用),但是在日志中却出现错误。

我在这里同时发布了屏幕截图和代码。

请帮助!

模拟器的屏幕截图

enter image description here

真实设备的屏幕截图

enter image description here

检查以下代码

@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 个答案:

没有答案