Dart generic constraints to several types and set default value Dart generic constraints to several types and set default value dart dart

Dart generic constraints to several types and set default value


No, and no.

Dart does not have multiple constraints or union types, so you can't have a type variable containing either bool or int, nor a normal variable allowing values of only those types.

Dart types also do not have any way to define default value.Use nullable types and null as the default value instead. All types in Dart are object types and can be made nullable by adding ?.