checkFilesAndShowToast method

Future<Widget?> checkFilesAndShowToast(
  1. int PjNr,
  2. InspectionLocation data,
  3. BuildContext context
)

Implementation

Future<Widget?> checkFilesAndShowToast(
    int PjNr, InspectionLocation data, BuildContext context) async {
  // Holen des App-Dokumentenverzeichnisses
  final directory = await getApplicationDocumentsDirectory();
  final basePath = directory.path;

  // Alle Ordner im Verzeichnis auflisten
  final baseDir = Directory(basePath);
  if (!await baseDir.exists())
    return nextModel<CheckCategory, InspectionLocation, CategoryModel>(
        generateNextModel(data));
  ;

  final folders = baseDir.listSync().whereType<Directory>();
  for (var folder in folders) {
    final folderName = folder.path.split(Platform.pathSeparator).last;
    debugPrint("Checking folder: ${folderName}");
    final regex = RegExp('^${PjNr}' + r'-[1-9]*-[1-9]*-0$');
    debugPrint("Checking folder: ${regex}");
    if (folderName.startsWith(regex)) {
      final file = folder.listSync().whereType<File>();
      if (file.isNotEmpty) {
        debugPrint("Found files in folder: ${folderName}");
        return showDialog(
            context: context,
            builder: (context) {
              return AlertDialog(
                title: Text("Gefundene Mängel"),
                content: Text(
                    "Diese Inspektion enthält bereits Mängel. Möchtest du sie wirklich bearbeiten?"),
                actions: [
                  TextButton(
                    onPressed: () {
                      Navigator.of(context).pop();
                      Navigator.of(context).pop();
                    },
                    child: Text("Abbrechen"),
                  ),
                  TextButton(
                    onPressed: () {
                      Navigator.of(context).pop();
                    },
                    child: Text("Trotzdem fortfahren"),
                  ),
                ],
              );
            });
      }
      break;
    }
  }

  ;
}