Flutter GridView设置宽高

GridView.count(
      padding: EdgeInsets.all(5.0),

      //一行多少个
      crossAxisCount: 5,

      //滚动方向
      scrollDirection: Axis.vertical,

      // 左右间隔
      crossAxisSpacing: 10.0,

      // 上下间隔
      mainAxisSpacing: 10.0,

      //宽高比
      childAspectRatio: 2 / 5,

      children: 
    );

 Flutter GridView设置宽高_第1张图片

 

 

Flexible(
                child: GridView.count(
                  scrollDirection: Axis.vertical,
                  padding: const EdgeInsets.only(left: 15,right: 15),
                  crossAxisCount: 4,
                  crossAxisSpacing: 6,
                  childAspectRatio: 3.5/2,
                  children: [
                    OutlinedButton(onPressed: (){setState(() {_quanbuState =!_quanbuState;});},
                        child: Text("全部",style: _quanbuState ? const TextStyle(color: Colors.blue,) : const TextStyle(color: Colors.grey),)),
                    OutlinedButton(onPressed: (){setState(() {_zaixian =!_zaixian;});},
                        child: Text("在线",style: _zaixian ? const TextStyle(color: Colors.blue,) : const TextStyle(color: Colors.grey),)),
                    OutlinedButton(onPressed: (){setState(() {_lixian =!_lixian;});},
                        child: Text("离线",style: _lixian ? const TextStyle(color: Colors.blue,) : const TextStyle(color: Colors.grey),)),
                    OutlinedButton(onPressed: (){setState(() {_guzhang =!_guzhang;});},
                        child: Text("故障",style: _guzhang ? const TextStyle(color: Colors.blue,) : const TextStyle(color: Colors.grey),),)
                  ],),
              ),

你可能感兴趣的:(flutter)