buildCommandInsideParent method

String buildCommandInsideParent()

Implementation

String buildCommandInsideParent() {
  final isAutoDispose = !command.isKeepAlive;

  if (_hasFamily) {
    // Family command inside parent: generate family provider with class
    final familyRecordType = _familyParams.toRecordType();
    return '''
Future<${command.dataType}> ${command.name}(${command.params.toParameterSignature()});

late final _\$${command.name}Command = NotifierProvider.family<${command.notifierType}, ${command.stateType}, $familyRecordType>(
  ($familyRecordType familyArg) => $_parentCommandClassName(this as ${parent!.name}, familyArg),
  isAutoDispose: $isAutoDispose,
);

$facadeCommandClassNameRef ${command.publicName}Command(${_familyParams.toParameterSignature()}) => $facadeCommandClassNameRef(ref, this as ${parent!.name}, ${_familyParams.toRecordValue()});''';
  }

  return '''
Future<${command.dataType}> ${command.name}(${command.params.toParameterSignature()});

late final _\$${command.name}Command = NotifierProvider<${command.notifierType}, ${command.stateType}>(
  () => $_parentCommandClassName(this as ${parent!.name}),
  isAutoDispose: $isAutoDispose,
);

$facadeCommandClassNameRef get ${command.publicName}Command => $facadeCommandClassNameRef(ref, this as ${parent!.name});''';
}