DEV Community

OLUWAYEMI FISAYO NATHANIEL
OLUWAYEMI FISAYO NATHANIEL

Posted on

Usage of onTap function in a listTile with Drawer

When making use of an onTap function in a ListTile widget in flutter: Use it this way:
Widget buildListTile(String text, IconData icon, Function() tapHandler) {
return ListTile(
leading: Icon(
icon,
size: 26,
),
title: Text(
text,
style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
),
onTap: tapHandler,
);
}

and not this way:

Widget buildListTile(String text, IconData icon, Function tapHandler) {
return ListTile(
leading: Icon(
icon,
size: 26,
),
title: Text(
text,
style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
),
onTap: tapHandler,
);
}

N.B : Look how i defined the function in both

the second way would run your code into errors while your code would be without errors in the first

Top comments (0)