I've created a class with 2 arguments, and 'title' is non-nullable and 'leading' is nullable.
So I defined two possible cases with if statement, for when 'leading' is null and not null.
(I refered this article: Understanding null safety | Dart)
But on VS Code, following error is continuously displayed:
The element type 'Icon?' can't be assigned to the list type 'Widget'. (dartlist_element_type_not_assignable)
What should I do to treat a null safety problem on this situation?
class MyPageListTile extends StatelessWidget {
final Text title;
final Icon? leading;
MyPageListTile({this.leading, required this.title});
@override
Widget build(BuildContext context) {
if (leading is Icon) {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [leading, SizedBox(width: 10), title]);
} else {
return Row(
crossAxisAlignment: CrossAxisAlignment.start, children: [title]);
}
}
}