if you could help me with this case please.
I am with this problem wanting to assign some icons and I am getting the following error
Home_page.dart
final categoryItem = _CategoryItem(
icon: servicesProvider.icons[category.icon],
label: category.name,
isSelected: servicesProvider.category.id == category.id,
onTap: () => servicesProvider.selectCategory(category),
);
services_provider.dart
final Map<String, IconData > icons = {
'scissors': FontAwesome.scissors,
'knife': RpgAwesome.knife,
'mask': FontAwesome5.mask,
'pump_soap': FontAwesome5.pump_soap,
'hand_sparkles': FontAwesome5.hand_sparkles,
'face': Icons.face,
'airline_seat_legroom_extra': Icons.airline_seat_legroom_extra,
'person_booth': FontAwesome5.person_booth,
};
Use a fallback icon or add a bang operator because servicesProvider.icons
's result might be nullable:
icon: servicesProvider.icons[category.icon] ?? Icon(Icons.add),
or
icon: servicesProvider.icons[category.icon]!,
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.