You can copy paste run full code below
You can use GlobalKey
and https://pub.dev/packages/icons_helper
Wither GlobalKey
to get current icon
and use icon_helper
to compare code point
and print
code snippet
var keyList = [
GlobalKey(),
GlobalKey(),
GlobalKey(),
GlobalKey(),
GlobalKey(),
GlobalKey()
];
return GridView.count(
crossAxisCount: 8,
children: List.generate(ls.length, (index) {
var iconData = ls[index];
return IconButton(
key: keyList[index],
onPressed: () {
IconButton iconbutton = keyList[index].currentWidget;
helper.IconsMap.forEach((k, v) {
var iconButton = iconbutton.icon as Icon;
if (v.codePoint == iconButton.icon.codePoint) {
print('${k}');
}
});
},
icon: Icon(
iconData,
output of click first two icon
I/flutter ( 6215): extension
I/flutter ( 6215): face
working demo

full code
import 'package:flutter/material.dart';
import 'package:icons_helper/icons_helper.dart' as helper;
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: ShowData(),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
class ShowData extends StatefulWidget {
@override
_ShowDataState createState() => _ShowDataState();
}
class _ShowDataState extends State<ShowData> {
_showIconGrid() {
var ls = [
Icons.extension,
Icons.face,
Icons.fastfood,
Icons.favorite,
Icons.favorite_border,
Icons.home,
];
var keyList = [
GlobalKey(),
GlobalKey(),
GlobalKey(),
GlobalKey(),
GlobalKey(),
GlobalKey()
];
return GridView.count(
crossAxisCount: 8,
children: List.generate(ls.length, (index) {
var iconData = ls[index];
return IconButton(
key: keyList[index],
onPressed: () {
IconButton iconbutton = keyList[index].currentWidget;
helper.IconsMap.forEach((k, v) {
var iconButton = iconbutton.icon as Icon;
if (v.codePoint == iconButton.icon.codePoint) {
print('${k}');
}
});
},
icon: Icon(
iconData,
));
}),
);
}
@override
Widget build(BuildContext context) {
return _showIconGrid();
}
}