I want to use my image from assets as an icon, and then I build my lists, but there are some errors that occurred when trying to add Image.asset
as a class to the icon as a variable with IconData
as data type, instead of using Icons as a class.
Any idea to fix this problem?
Thank you.
class Menu {
const Menu({this.icon, this.title});
final IconData icon;
final String title;
}
const List<Menu> menus = const <Menu>[
const Menu(title: 'menu_icon_1', icon: Image.asset('assets/menu/1-1.png')),
],
error: The argument type 'Image' can't be assigned to the parameter type 'IconData'. (argument_type_not_assignable at [sinergi] lib\home.dart:12)
please use ImageIcon
class Menu {
const Menu({this.icon, this.title});
final ImageIcon icon;
final String title;
}
const List<Menu> menus = const <Menu>[
const Menu(title: 'menu_icon_1', icon: ImageIcon(AssetImage('assets/menu/1-1.png'))),
];