import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; class GridButtons extends StatefulWidget { final List gridList; final int crossCount; GridButtons({Key key, this.crossCount, this.gridList}) : super(key: key); @override _GridButtonsState createState() => _GridButtonsState(); } class GridButton { String title; String path; VoidCallback onTap; GridButton(this.title, this.path, this.onTap); } class _GridButtonsState extends State { @override Widget build(BuildContext context) { return GridView.builder( padding: EdgeInsets.zero, shrinkWrap: true, physics: NeverScrollableScrollPhysics(), itemCount: widget.gridList.length, itemBuilder: (BuildContext context, int index) { return InkWell( onTap: widget.gridList[index].onTap, child: Container( alignment: Alignment.center, child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ Image.asset( widget.gridList[index].path, height: 53.w, width: 53.w, fit: BoxFit.cover, ), SizedBox(height: 5), Text( widget.gridList[index].title, style: TextStyle(fontSize: 24.sp), ) ], ), ), ); }, gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: widget.crossCount, mainAxisSpacing: 6.0, childAspectRatio: 1.0), ); } }