appendImportMain function

void appendImportMain()

Implementation

void appendImportMain() {
  final filePath = 'lib/main.dart';
  // Read the contents of the file
  final file = File(filePath);
  String contents = file.readAsStringSync();
  if (contents
      .contains('package:flutter_easyloading/flutter_easyloading.dart')) {
    return;
  }

  // Find the index of the last import statement
  final lastImportIndex = contents.lastIndexOf('import ');

  String importFile = """
  import 'package:flutter_easyloading/flutter_easyloading.dart';
  import 'helpers/state_util.dart';
  """;
  // Insert the string after the last import statement
  contents =
      contents.replaceRange(lastImportIndex, lastImportIndex, importFile);

  // Write the modified contents back to the file
  file.writeAsStringSync(contents);
}