TogeFileUploadWidget class

A widget that provides a customizable file upload interface with support for:

  • Uploading from multiple sources (camera, gallery, file picker)
  • Custom file validation
  • Replacing and deleting uploaded files
  • System tray integration for source selection

Sample usage:

TogeFileUploadWidget(
  uploadTitle: 'Upload your files',
  maxFileSizeInMB: 10,
  maxUpload: 5,
  sources: [
    TogeFileUploadSource.camera,
    TogeFileUploadSource.gallery,
    TogeFileUploadSource.files,
  ],
  subLabelOne: 'Max file size: 10MB',
  subLabelTwo: 'Max 5 files',
  allowedFileTypes: [
    TogeFileUploadFileType.image,
    TogeFileUploadFileType.video,
  ],
  onFilesChanged: (files) {
    - Handle file changes
  },
  onUploadTap: () async {
    return true; // Proceed with file upload
  },
  errorMessageBuilder: (file, isValidSize, isValidFileType) {
    if (!isValidSize) {
    return 'File size exceeds the limit';
  }
  if (!isValidFileType) {
    return 'File type is not allowed';
  }
    return null; // No error
  },
);

Users can configure:

  • Maximum number of uploads
  • Maximum file size
  • Allowed file types
  • Upload and sub-label texts
  • Custom upload icon
  • Duplicate file prevention
  • Callback when files are selected
  • Custom error message generation
Inheritance

Constructors

TogeFileUploadWidget({Key? key, required String uploadTitle, String? systemTrayTitle, List<TogeFileUploadSource>? sources, String? title, Widget? uploadIconWidget, int maxFileSizeInMB = 5, String? errorMessageBuilder(File file, bool isValidSize, bool isValidFileType)?, int maxUpload = 1, bool isModalDismissible = true, String? subLabelOne, String? subLabelTwo, List<TogeFileUploadFileType>? allowedFileTypes, bool allowDuplicateFiles = false, void onFilesChanged(List<TogeFileUploadEntity> files)?, void onFileAdded(TogeFileUploadEntity file)?, void onFileRemoved(TogeFileUploadEntity file)?, void onFileReplaced(TogeFileUploadEntity oldFile, TogeFileUploadEntity newFile)?, void onReplaceTap(int index, TogeFileUploadSource source)?, Future<bool> onUploadTap()?, List<TogeFileUploadEntity>? initialFiles, String? takePhotoLabel, String? photoGalleryLabel, String? fileStorageLabel, String? replaceFileLabel, bool viewOnly = false})
const

Properties

allowDuplicateFiles bool
Whether to allow duplicate files by name or path.
final
allowedFileTypes List<TogeFileUploadFileType>?
Optional list of allowed file types.
final
errorMessageBuilder String? Function(File file, bool isValidSize, bool isValidFileType)?
Optional builder for custom error messages based on validation. This will trigger on every file changes.
final
fileStorageLabel String?
Optional label for the "File Storage" button in the system tray. Defaults to 'File Storage'.
final
hashCode int
The hash code for this object.
no setterinherited
initialFiles List<TogeFileUploadEntity>?
Optional initial files to pre-populate the upload list. This can be used to display files that have already been uploaded or selected.
final
isModalDismissible bool
Whether the file upload modal can be dismissed by the user.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
maxFileSizeInMB int
Maximum file size allowed in megabytes.
final
maxUpload int
Maximum number of files that can be uploaded.
final
onFileAdded → void Function(TogeFileUploadEntity file)?
Optional callback triggered when a file is added.
final
onFileRemoved → void Function(TogeFileUploadEntity file)?
Optional callback triggered when a file is removed.
final
onFileReplaced → void Function(TogeFileUploadEntity oldFile, TogeFileUploadEntity newFile)?
Optional callback triggered when a file is replaced.
final
onFilesChanged → void Function(List<TogeFileUploadEntity> files)?
Optional callback triggered when files changed.
final
onReplaceTap → void Function(int index, TogeFileUploadSource source)?
Optional callback triggered when the replace button is pressed for a specific file.
final
onUploadTap Future<bool> Function()?
Optional callback executed before file picking begins. Returning false cancels it.
final
photoGalleryLabel String?
Optional label for the "Photo Gallery" button in the system tray. Defaults to 'Photo Gallery'.
final
replaceFileLabel String?
Optional label for the "Replace File" button in the system tray. Defaults to 'Replace'.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sources List<TogeFileUploadSource>?
Available upload sources for the file upload widget. This can be a combination of:
final
subLabelOne String?
Optional first sublabel below the upload title.
final
subLabelTwo String?
Optional second sublabel below the upload title.
final
systemTrayTitle String?
Optional system tray title shown in the modal.
final
takePhotoLabel String?
Optional label for the "Take Photo" button in the system tray. Defaults to 'Take a Photo'.
final
title String?
Optional title shown above the upload area.
final
uploadIconWidget Widget?
Optional widget used to display an upload icon.
final
uploadTitle String
Main label shown in the upload area.
final
viewOnly bool
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<TogeFileUploadWidget>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited