save method

  1. @override
Future<List<FilesModel>> save({
  1. String toDirectory = '',
  2. String fromPath = "",
  3. File? fromFile,
  4. FilesModel? fromData,
  5. List<String> fromPaths = const [],
  6. List<File> fromFiles = const [],
  7. List<FilesModel> fromDataList = const [],
  8. AndroidPathOptions? androidPathOptions,
})
override

Future method save has String _ fromPath has String _ toDirectory has File _ fromFile has FilesModel _ fromData has List of String_ fromPaths has List of File_ fromFiles has List of FilesModel_ fromDataList has AndroidPathOptions _ androidPathOptions has List of FilesModel return Value

Implementation

@override
Future<List<FilesModel>> save(
    {String toDirectory = '',
    String fromPath = "",
    File? fromFile,
    FilesModel? fromData,
    List<String> fromPaths = const [],
    List<File> fromFiles = const [],
    List<FilesModel> fromDataList = const [],
    AndroidPathOptions? androidPathOptions}) async {
  List<FilesModel> successList = [];
  if (fromPath.isEmpty &&
      fromData == null &&
      fromFile == null &&
      fromPaths.isEmpty &&
      fromFiles.isEmpty &&
      fromDataList.isEmpty) {
    successList.add(FilesModel("Source Data", "No Source Data Found"));
    return successList;
  } else {
    List<FilesModel> fSourceList = [];
    final fCache = await getCacheDirectory();
    if (fromPath.isNotEmpty) {
      final fPName = _checkFilePath(fromPath);
      if (fPName.isNotEmpty) {
        final fS = FilesModel(fPName, fromPath);
        fSourceList.add(fS);
      }
    }
    if (fromFile != null) {
      final fPName = _checkFilePath(fromFile.path);
      if (fPName.isNotEmpty) {
        final fS = FilesModel(fPName, fromFile.path);
        fSourceList.add(fS);
      }
    }
    if (fromData != null) {
      if (fromData.value.isNotEmpty) {
        final fPName = _checkFilePath(fromData.value);
        if (fPName.isNotEmpty) {
          final fS = FilesModel(fPName, fromData.value);
          fSourceList.add(fS);
        }
      } else if (fromData.data != null) {
        if (fromData.valueName.isNotEmpty &&
            fromData.data!.isNotEmpty &&
            fromData.valueName.split(".").isNotEmpty) {
          if (fCache.contains("/cache")) {
            final fFile = File(joinPath(fCache, fromData.valueName));
            fFile.writeAsBytesSync(fromData.data!);
            final fPName = _checkFilePath(fFile.path);
            if (fPName.isNotEmpty) {
              final fS = FilesModel(fPName, fFile.path);
              fSourceList.add(fS);
            }
          }
        }
      }
    }
    if (fromPaths.isNotEmpty) {
      for (var i in fromPaths) {
        final fPName = _checkFilePath(i);
        if (fPName.isNotEmpty) {
          final fS = FilesModel(fPName, i);
          fSourceList.add(fS);
        }
      }
    }
    if (fromFiles.isNotEmpty) {
      for (var i in fromFiles) {
        final fPName = _checkFilePath(i.path);
        if (fPName.isNotEmpty) {
          final fS = FilesModel(fPName, i.path);
          fSourceList.add(fS);
        }
      }
    }
    if (fromDataList.isNotEmpty) {
      for (var i in fromDataList) {
        if (i.value.isNotEmpty) {
          final fPName = _checkFilePath(i.value);
          if (fPName.isNotEmpty) {
            final fS = FilesModel(fPName, i.value);
            fSourceList.add(fS);
          }
        } else if (i.data != null) {
          if (i.valueName.isNotEmpty &&
              i.data!.isNotEmpty &&
              i.valueName.split(".").isNotEmpty) {
            if (fCache.contains("/cache")) {
              final fFile = File(joinPath(fCache, i.valueName));
              fFile.writeAsBytesSync(i.data!);
              final fPName = _checkFilePath(fFile.path);
              if (fPName.isNotEmpty) {
                final fS = FilesModel(fPName, fFile.path);
                fSourceList.add(fS);
              }
            }
          }
        }
      }
    }
    if (fSourceList.isNotEmpty) {
      AndroidPathOptions jAndroidPathOptions = AndroidPathOptions();
      if (androidPathOptions != null) {
        jAndroidPathOptions = androidPathOptions;
      }
      final aVal = await _saveMainMethod(
          dataList: fSourceList,
          saverPathSettings: jAndroidPathOptions,
          toDirectory: toDirectory);
      if (aVal.isNotEmpty) {
        for (var i in aVal) {
          successList.add(FilesModel.fromMap(json.decode(i)));
        }
      }
      return successList;
    } else {
      successList.add(FilesModel("Source Data", "No Source Data Found"));
      return successList;
    }
  }
}