In Flutter I have Gridview with three static containers. I am trying to achieve tap action in the Container. The container have Image and Text. I tried with Inkwell.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: "4.0",
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: GridView.count(
crossAxisCount: 3,
children: [
Container(
color: Colors.green,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.work,
color: Colors.white,
size: 60,
),
Text("Work ", style: TextStyle(color: Colors.white, fontSize: 18))
],
),
),
Container(
color: Colors.green,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Icon(
Icons.account_circle,
color: Colors.white,
),
Text("Account", style: TextStyle(color: Colors.white))
],
),
),
Container(
color: Colors.green,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Icon(
Icons.message,
color: Colors.white,
),
Text("Messages", style: TextStyle(color: Colors.white))
],
),
),
],
shrinkWrap: true,
mainAxisSpacing: 10,
crossAxisSpacing: 10,
)));
}
I am not sure about where to set InkWell in the container. I am bit new to Flutter, Any suggestions would be helpful.
First for cleaner code make widget from your container like this:
then use it like this: