getDartType method

String getDartType({
  1. bool? isOptional,
})

Returns the expression to use for the Dart type.

Implementation

String getDartType({bool? isOptional}) {
  final String optional = isOptional == true || isNullableOptional ? '?' : '';
  if (baseType.isTimestamp && parent.fileGen!.useBetterProtos) {
    return '$coreImportPrefix.DateTime$optional';
  } else if (baseType.isDuration && parent.fileGen!.useBetterProtos) {
    return '$coreImportPrefix.Duration$optional';
  }
  if (isMapField) {
    final d = baseType.generator as MessageGenerator;
    final keyType = d._fieldList[0].baseType.getDartType(parent.fileGen!);
    final valueType = d._fieldList[1].baseType.getDartType(parent.fileGen!);
    return '$coreImportPrefix.Map<$keyType, $valueType>$optional';
  }
  if (isRepeated) {
    return baseType.getRepeatedDartType(parent.fileGen!) + optional;
  }
  return baseType.getDartType(parent.fileGen!) + optional;
}