unpackArgAST function

String unpackArgAST(
  1. AstType type,
  2. String variableName, {
  3. bool maybeNull = false,
})

Implementation

String unpackArgAST(AstType type, String variableName,
    {bool maybeNull = false}) {
  final questionMark =
      kEnableNullSafety == false || maybeNull == true ? '?' : '';
  if (type is AstCustomType) {
    return '$variableName$questionMark.encode()';
  } else if (type is AstList) {
    if (type.generics.isNotEmpty) {
      return '$variableName$questionMark.map((e) => ${unpackArgAST(type.generics.first, 'e')}).toList()';
    }
  } else if (type is AstMap && type.generics.isNotEmpty) {
    return '$variableName as ${type.dartType(showGenerics: true)}';
  } else if (type is AstVoid) {
    return '';
  }
  return '$variableName as ${type.dartType()}';
}