'Serializing a variable inside a generic class in Dart with NNBD
I have a generic class MyClass<T> which can serialize and deserialize values of type T via Serializers class. Before migrating to NNBD constructing a serializer was straightforward:
MyClass<T> {
Serializer serializer() => serializers.serializerForType(T);
...
}
This sill works in cases when MyClass is instantiated with a non-nullable type (e.g. MyClass<Foo>). But with a nullable type (e.g. MyClass<Foo?>) serializers.serializerForType(T) returns null. Apparently Foo and Foo? are considered different types, hence the serializer is not found.
Is it possible to get a non-nullable type given a nullable type (I've only found this answer but it didn't help) or otherwise get the serializer?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
