首页 > 解决方案 > Fultter GridView 滚动

问题描述

我尝试设置物理以启用滚动功能,但它会滚动整个屏幕。
只有红色框可以滚动
如何设置另一个 Widget 是固定位置,只能在 GridView 中启用滚动?
只想在 GridView 中滚动,请参考照片,这样理解更清楚。

child: Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text('Sanfield Mobile App'),
        actions: <Widget>[
            IconButton(
              icon: Icon(
                Icons.exit_to_app,
                color: Colors.white,
              ),
              onPressed: () {
                showConfirmLogoutDialog(context,'Confirm logout','Do you want to logout?');
            },
          )
        ],
      ),
      drawer: CustomDrawer(),
        body:SingleChildScrollView(
            physics: new NeverScrollableScrollPhysics(),
            child:Column(
            children: <Widget>[
            Card(
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: <Widget>[
                  ListTile(
                  leading: 
                  image(),
                  title: Text(updateDate),
                  subtitle: Text(weatherDetails),
                ),
              Row(
                mainAxisAlignment: MainAxisAlignment.end,
                children: <Widget>[
                  RichText(
                    text: TextSpan(
                      style: new TextStyle(
                      fontSize: 24.0,
                      color: Colors.black,
                    ),
                  children: <TextSpan>[
                    TextSpan(text: mintemp.toString()+' C - ', style: new TextStyle(color: Colors.lightBlue)),
                    TextSpan(text: maxtemp.toString()+' C ', style: new TextStyle(color: Colors.red)),
                    TextSpan(text: '       Update:'+updateTime, style: new TextStyle(color: Colors.black,fontSize: 14)),
                ],
              ),
              ), 
              ],
            ),
          ],
        ),
      ),
      Container(
        height: 80,
            child: new ListView.builder(
              itemCount: 6,
              itemBuilder: (context, index){
                return new Card(child: new Container(
                //width: MediaQuery.of(context).size.width,
                 width:320,
                 height: 80,
                 child: new Text('Hello'),alignment: Alignment.center,));
              }, scrollDirection: Axis.horizontal,
            ),
          ), 
          Container(  
            height: 889,
           child:GridView.count(
                    physics: ScrollPhysics(),
                    primary: false,
                    padding: const EdgeInsets.all(10),
                    crossAxisSpacing: 10,
                    mainAxisSpacing: 10,
                    crossAxisCount: 3,
                    children: <Widget>[
                      Container(
                        padding: const EdgeInsets.all(20),
                        decoration: BoxDecoration(
                          image: DecorationImage(
                            image: AssetImage(
                                'images/hkphoto.jpg'),
                            fit: BoxFit.fill,
                          ),
                          shape: BoxShape.circle,
                        ),
                        child: InkWell(
                          /*onTap: () => Navigator.push(
                              context, MaterialPageRoute(builder: (context) =>)
                            ),*/ // handle your onTap here
                        ),
                      ),
                      InkWell(
                          child:Container(
                                    padding: const EdgeInsets.all(8),
                                    child: const Text('phs'),
                                    color: Colors.teal[200],
                          ),
                          /*onTap: () => Navigator.push(
                              context, MaterialPageRoute(builder: (context) => 
                            )
                          ),*/
                      ),
                      InkWell(
                        child:Container(
                          padding: const EdgeInsets.all(8),
                          child: const Text('whs'),
                          color: Colors.teal[200],
                        ),
                        /*onTap: () => Navigator.push(
                            context, MaterialPageRoute(builder: (context) => 
                          ),
                        ),*/
                      ),
                      InkWell(
                        child:Container(
                          padding: const EdgeInsets.all(8),
                          child: const Text('whs'),
                          color: Colors.teal[200],
                        ),
                        /*onTap: () => Navigator.push(
                            context, MaterialPageRoute(builder: (context) => 
                          ),
                        ),*/
                      ),
                      InkWell(
                        child:Container(
                          padding: const EdgeInsets.all(8),
                          child: const Text('whs'),
                          color: Colors.teal[200],
                        ),
                        /*onTap: () => Navigator.push(
                            context, MaterialPageRoute(builder: (context) => 
                          ),
                        ),*/
                      ),
                      InkWell(
                        child:Container(
                          padding: const EdgeInsets.all(8),
                          child: const Text('whs'),
                          color: Colors.teal[200],
                        ),
                        /*onTap: () => Navigator.push(
                            context, MaterialPageRoute(builder: (context) => 
                          ),
                        ),*/
                      ),
                ],
              )
              ),
            ]
          ),
        )
      )

标签: flutterdartscrollwidget

解决方案


删除SingleChildScrollViewbody 顶层的 并将 的设置scrollPhysics为。GridViewAlwaysScrollableScrollPhysics()


推荐阅读