getAssociationMethod method

String getAssociationMethod(
  1. DartType argType, {
  2. bool forceNullable = false,
  3. required String query,
})
inherited

Implementation

String getAssociationMethod(
  DartType argType, {
  bool forceNullable = false,
  required String query,
}) {
  final isNullable = argType.nullabilitySuffix != NullabilitySuffix.none;
  var repositoryOperator = isNullable ? '?' : '!';
  if (repositoryHasBeenForceCast) repositoryOperator = '';

  final thenStatement =
      forceNullable || isNullable ? 'r?.isNotEmpty ?? false ? r!.first : null' : 'r!.first';

  return '''repository
    $repositoryOperator.getAssociation<${SharedChecker.withoutNullability(argType)}>($query)
    .then((r) => $thenStatement)
  ''';
}