I think it would be very confusing if calling a constructor (or
factory constructor) could end up returning a null object. If an
object cannot be instantiated by the constructor, it should instead be
an exception which can then then be handled.
An alternative solution would be to make a static method in your class
which can then be used to create the object (maybe make the
constructor private). This static method could be called "tryWrap" (I
am bad at naming things...) and can have the signature "Wrap?
tryWrap(T a)" which makes it clear that the method can return null.
This design can e.g. be seen on int.tryParse().
> --
> For more ways to connect visit
https://dart.dev/community
> ---
> You received this message because you are subscribed to the Google Groups "Dart Misc" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
misc+uns...@dartlang.org.
> To view this discussion on the web visit
https://groups.google.com/a/dartlang.org/d/msgid/misc/5eccbe38-0958-45dd-b767-03f7a9a3b03en%40dartlang.org.
--
Jacob Bang / julemand101