Issue
I'm trying to make an interface with Dart Flutter. I made an interface like this:
I want these items to be clickable. When clicked, I will take action. What can I do so that items can be clicked?
Codes:
body: Center(
child: GridView.builder(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
),
itemCount: subjects.length,
itemBuilder: (BuildContext context, int index) {
return Container(
child: Card(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(subjects[index].subjectImage, fit: BoxFit.cover, height: 50, width: 50,),
SizedBox(height: 10,),
Text(subjects[index].subjectName, style: TextStyle(fontSize: 20),),
],
),
),
);
},
),
)
Solution
You can use GestureDetector or Inkwell for this.And write your onpress action code in onTap().
GestureDetector(
onTap: () {
// To do
},
child: Card(
),
),
or
InkWell(
onTap: () {
// To do
},
child: Card(),
),
Answered By - Sobin Benny
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.