checkFileExistenceAsync static method

Future<bool> checkFileExistenceAsync({
  1. required String filePath,
})

  1. Replace MaterialApp


  1. Check File / Folder Existence

Implementation

// static Future<void> replaceMaterialApp(
//   String filePath,
//   String newReturnWidget,
// ) async {
//   try {
//     final file = File(filePath);

//     if (!await file.exists()) {
//       print('❌ File not found: $filePath');
//       return;
//     }

//     final content = await file.readAsString();
//     final materialReturnRegex = RegExp(
//       r'return\s+MaterialApp\s*\(([\s\S]*?)\);',
//       multiLine: true,
//     );

//     if (!materialReturnRegex.hasMatch(content)) {
//       print('⚠️ No MaterialApp return widget found to replace');
//       return;
//     }

//     final updatedContent = content.replaceAll(
//       materialReturnRegex,
//       "return $newReturnWidget",
//     );

//     await file.writeAsString(updatedContent);
//     print('✅ MaterialApp replaced correctly');
//   } catch (e) {
//     print('❌ Error replacing MaterialApp: $e');
//   }
// }

///---------------------------------------------------------------------------
/// 5. Check File / Folder Existence
///---------------------------------------------------------------------------
static Future<bool> checkFileExistenceAsync({
  required String filePath,
}) async {
  return await File(filePath).exists();
}