avoid_ type_ to_ string
Saiba mais sobre a regra de lint avoid_type_to_string.
Evite
Detalhes
#
FAÇA evitar chamadas a
RUIM:
void bar(Object other) {
if (other.runtimeType.toString() == 'Bar') {
doThing();
}
}
Object baz(Thing myThing) {
return getThingFromDatabase(key: myThing.runtimeType.toString());
}
BOM:
void bar(Object other) {
if (other is Bar) {
doThing();
}
}
class Thing {
String get thingTypeKey => ...
}
Object baz(Thing myThing) {
return getThingFromDatabase(key: myThing.thingTypeKey);
}
Ativar
#
Para ativar a regra avoid_type_to_string, adicione avoid_type_to_string em
linter > rules no seu arquivo analysis_options.yaml:
linter:
rules:
- avoid_type_to_string
Se você usa a sintaxe de mapa YAML para configurar as regras de lint,
adicione avoid_type_to_string: true em linter > rules:
linter:
rules:
avoid_type_to_string: true
Salvo indicação em contrário, a documentação neste site reflete Dart 3.13.7. Relatar um problema.
Encontrou essa página sem tradução ou que precisa de correção? Abra uma issue e nos ajude a manter esse site em PT-BR para ajudar pessoas como você.