AppFile constructor

AppFile({
  1. required String fileKey,
  2. String? fileName,
  3. String? filePath,
  4. Uint8List? fileBytes,
})

Implementation

AppFile({
  required this.fileKey,
  this.fileName,
  String? filePath, // For mobile (local file path)
  Uint8List? fileBytes, // For web (binary file data)
}) {
  if (filePath != null) {
    // Mobile: Extract details from file path
    fileName = fileName ?? filePath.split("/").last;
    fileExtension = filePath.split(".").last;
    this.filePath = filePath;
    fileType = "file"; // Type for local file path
  } else if (fileBytes != null) {
    // print("inside file web bytes $fileBytes");
    // Web: Handle file bytes (fileName and extension must be set manually)
    this.fileBytes = fileBytes;
    fileName = fileName ?? "image.png";
    fileType = "binary"; // Type for file bytes
  } else {
    throw ArgumentError("Either filePath or fileBytes must be provided.");
  }
}