-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Description
I declared:
extension OrDefault<T> on T {
T get orDefault {
final value = this;
if (value == null) {
return {
int: 0,
String: '',
double: 0.0,
num: 0,
bool: false,
Map: {},
List: [],
Set: {},
}[T] as T;
} else {
return value;
}
}
}
test('Test ObjectExtension.orDefault()', () async {
const int? nullInt = null;
expect(nullInt.orDefault, 0); // fails since T is int? and returns null instead of 0.
});
Metadata
Metadata
Assignees
Labels
No labels