0

我无法滚动查看我的下部网格视图。这是为什么?我应该改变什么才能使这项工作?请帮忙!!!先感谢您。

Scaffold(
            body: SingleChildScrollView(
              child: Container(
                child: Column(
                  children: <Widget>[
                    Text('GridView 1'),
                    GridView.count(
                      crossAxisCount: 3,
                      shrinkWrap: true,
                      children: List.generate(
                        9,
                        (index) {
                          return TouchableImageCard(
                            imagePath: 'assets/images/view_${index + 1}.jpg',
                          );
                        },
                      ),
                    ),
                    Text('GridView 2'),
                    GridView.builder(
                      itemCount: list_item.length,
                      shrinkWrap: true,
                      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                          crossAxisCount: 3),
                      itemBuilder: (BuildContext context, int index) {
                        return TouchableImageCard(
                          imagePath: 'assets/images/view_${index + 1}.jpg',
                          // width: 150,
                          // height: 150,
                        );
                      },
                    ),
                  ],
                ),
              ),
            ),
          );

谢谢你帮助我扑腾。

4

2 回答 2

1

It actually does work, just not the way you need it.
The problem is that GridView itself is a scrollable widget too. So when you try to scroll the page, it actually tries to scroll those GridViews and not the SingleChildScrollView.
To disable GridView scrolling ability - you need to add one more parameter.

GridView.count(
                physics: NeverScrollableScrollPhysics(),
                ...
              ),
于 2020-08-11T04:50:38.867 回答
0

尝试这个:

 Center(
    child: SingleChildScrollView(
      padding: const EdgeInsets.all(8.0),
      child: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[]
于 2020-08-11T04:42:52.243 回答