addConstructorToController static method
void
addConstructorToController(
{ - required String path,
- required String providerName,
})
Implementation
static void addConstructorToController({
required String path,
required String providerName,
}) {
String import =
'''import '../../../data/providers/${providerName}_provider.dart';''';
final file = File(path);
if (file.existsSync()) {
final lines = file.readAsLinesSync();
lines.insert(2, import);
int index = lines.indexWhere((element) {
element = element.trim();
return element.startsWith(
'class ${providerName.pascalCase}Controller extends GetxController');
});
index++;
lines.insert(index,
''' ${providerName.pascalCase}Controller({required ${providerName.pascalCase}Provider ${providerName.camelCase}Provider})
: _${providerName.camelCase}Provider = ${providerName.camelCase}Provider;
final ${providerName.pascalCase}Provider _${providerName.camelCase}Provider;''');
file.writeAsStringSync(lines.join('\n'));
}
}