addDependencyToBinding static method
void
addDependencyToBinding(
- String path,
- String providerName
)
Implementation
static void addDependencyToBinding(String path, String providerName) {
String import =
'''import '../../../data/providers/${providerName}_provider.dart';''';
var file = File(path);
var lines = file.readAsLinesSync();
lines.insert(2, import);
var index = lines.indexWhere((element) {
element = element.trim();
return element.startsWith('void dependencies() {');
});
index++;
lines.insert(index, ''' Get.lazyPut<${providerName.pascalCase}Provider>(
() => ${providerName.pascalCase}Provider(
restClientDio: Get.find(),
),
);''');
final indexController = lines.indexWhere((element) {
element = element.trim();
return element.startsWith('() => ${providerName.pascalCase}Controller()');
});
lines[indexController] =
''' () => ${providerName.pascalCase}Controller(
${providerName.camelCase}Provider: Get.find(),
),''';
file.writeAsStringSync(lines.join('\n'));
}