Estou tentando descobrir se widget.onChanged
of RadioListTile<T>
não é nulo, mas parece que o dart é muito rigoroso quando se trata de genéricos. Alguma sugestão de como posso verificar isso?
(Sou um pouco novo no Fluter/Dart)
void testWidgetOnNUllDynamic(dynamic clbk) {
if (clbk != null) {
print('not null');
}
}
void testWidgetOnNUllCallback(Widget widget) {
if (widget is RadioListTile) {
// if (widget.onChanged != null) {
// //type '(String?) => void' is not a subtype of type '((dynamic) => void)?'
// print('Crash here');
// }
//attempt to erase the type
testWidgetOnNUllDynamic(widget.onChanged);
}
}
//This method is redundant
void testIfOnChangeIsNull(Widget widget) {
testWidgetOnNUllCallback(widget);
}
test('when widget is RadioListTile onChange test', () {
// <String> - Can be anything
RadioListTile<String> widget = RadioListTile(value: 'value', activeColor: 0, toggleable: true, onChanged:(value) => debugPrint('Test'), groupValue: null,);
testIfOnChangeIsNull(widget);
});
Acho que entendi o erro, mas não tenho certeza de como evitá-lo OU como verificar a inalienabilidade sem lançá-lo em um tipo concreto.
Fiz a mesma pergunta aqui.
Obrigado.