getDefaultValue function

Object? getDefaultValue(
  1. Type type
)

Gets a default value for a type

Implementation

Object? getDefaultValue(Type type) {
  if (type == int) return 0;
  if (type == double) return 0.0;
  if (type == String) return '';
  if (type == bool) return false;
  if (isCollectionType(type)) {
    if (type.toString().contains('List')) return <dynamic>[];
    if (type.toString().contains('Set')) return <dynamic>{};
    if (type.toString().contains('Map')) return <dynamic, dynamic>{};
  }
  return null;
}