iterableCast static method

String iterableCast(
  1. DartType argType, {
  2. bool isSet = false,
  3. bool isList = false,
  4. bool isFuture = false,
  5. bool forceCast = false,
})

Cast mapped values to their desired output value

Implementation

static String iterableCast(
  DartType argType, {
  bool isSet = false,
  bool isList = false,
  bool isFuture = false,
  bool forceCast = false,
}) {
  final nullableSuffix = argType.nullabilitySuffix != NullabilitySuffix.none ? '?' : '';
  var castStatement = nullableSuffix;
  if (isSet || isList) {
    final method = isSet ? 'Set' : 'List';
    castStatement += '.to$method()';
  }

  if (forceCast) {
    final castType = isFuture ? 'Future<$argType>' : argType;
    castStatement += '.cast<$castType>()';
  }

  return castStatement;
}