withoutNullResultType property

String get withoutNullResultType

Returns the final version of a type without decoration. It will not have a null suffix.

For example, Future<String>, List<Future<String>>, String? and Future<String?> will all return String.

Implementation

String get withoutNullResultType {
  final typeRemover = RegExp(r'\<[,\s\w]+\>');

  // Future<?>, Iterable<?>
  if (isFuture || isIterable) {
    final checker = SharedChecker<_SiblingModel>(argType);
    return checker.withoutNullResultType;
  }

  if (toJsonMethod != null) {
    return withoutNullability(toJsonMethod!.returnType).replaceAll(typeRemover, '');
  }

  // remove arg types as they can't be declared in final fields
  return withoutNullability(targetType).replaceAll(typeRemover, '');
}