FileSizeValidator class

FileSizeValidator extends TranslatedValidator to validate if a file size string is within a specified maximum size.

This validator checks if the file size, parsed from the string, does not exceed the maximum size limit.

Parameters:

  • maxSize The maximum allowed file size in bytes.
  • base1024Conversion Whether to use base 1024 (true) or base 1000 (false) for the conversion.
  • errorText The error message returned if the validation fails.
  • checkNullOrEmpty Whether to check if the value is null or empty.
Inheritance

Constructors

FileSizeValidator.new(int maxSize, {bool base1024Conversion = true, String? errorText, bool checkNullOrEmpty = true})
Constructor for the file size validator.
const

Properties

base1024Conversion bool
Whether to use base 1024 (true) or base 1000 (false) for the conversion.
final
checkNullOrEmpty bool
Whether to check if the value is null or empty.
finalinherited
errorText String
The error message returned if the value is invalid.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
maxSize int
The maximum allowed file size in bytes.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
translatedErrorText String
The translated error message returned if the value is invalid.
no setteroverride

Methods

formatBytes(int bytes) String
Helper function to format bytes into a human-readable string (e.g., KB, MB, GB).
isNullOrEmpty(String? valueCandidate) bool
Checks if the value is null or empty. Returns true if the value is null or empty, otherwise false. The value is considered empty if it is a String, Iterable, or Map and it is empty or contains only whitespace characters. If the value is not a String, Iterable, or Map, it is considered empty if it is null.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
validate(String? valueCandidate) String?
Validates the value and checks if it is null or empty.
inherited
validateValue(String valueCandidate) String?
Validates the value. Returns null if the value is valid, otherwise an error message. Call validate() instead of this method when using the validator.
override

Operators

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