Invalid type argument in constant list, map, or set literalDRT-W1440
The analyzer produces this diagnostic when a type parameter is used as a
type argument in a list, map, or set literal that is prefixed by const
.
This isn't allowed because the value of the type parameter (the actual type
that will be used at runtime) can't be known at compile time.
Examples
The following code produces this diagnostic because the type parameter T
is being used as a type argument when creating a constant list:
List<T> newList<T>() => const <T>[];
The following code produces this diagnostic because the type parameter T
is being used as a type argument when creating a constant map:
Map<String, T> newSet<T>() => const <String, T>{};
The following code produces this diagnostic because the type parameter T
is being used as a type argument when creating a constant set:
Set<T> newSet<T>() => const <T>{};
Common fixes
If the type that will be used for the type parameter can be known at compile time, then remove the type parameter:
List<int> newList() => const <int>[];
If the type that will be used for the type parameter can't be known until
runtime, then remove the keyword const
:
List<T> newList<T>() => <T>[];