DataValidation class Worksheet

An input rule applied to a cell range: a dropdown list, a numeric/length bound, a date/time constraint, or a custom formula.

Attach one with Sheet.setDataValidation (range-aware) or cell.dataValidation = ... (single cell). Rules survive a read/save round-trip.

sheet.setDataValidation(
  CellIndex.indexByString('C2'),
  DataValidation.list(['Low', 'Medium', 'High'], prompt: 'Pick one'),
  end: CellIndex.indexByString('C100'),
);

Constructors

DataValidation.custom(String formula, {bool allowBlank = true, String? prompt, String? promptTitle, String? error, String? errorTitle, DataValidationErrorStyle errorStyle = DataValidationErrorStyle.stop})
Allow entries only where the boolean formula is true, e.g. 'ISNUMBER(A1)' or 'A1>TODAY()'.
factory
DataValidation.decimal({num? min, num? max, DataValidationOperator operator = DataValidationOperator.between, bool allowBlank = true, String? prompt, String? promptTitle, String? error, String? errorTitle, DataValidationErrorStyle errorStyle = DataValidationErrorStyle.stop})
Allow only decimal numbers. With the default between operator pass both min and max; for one-sided operators pass the single relevant bound.
factory
DataValidation.list(List<String> values, {bool allowBlank = true, bool showDropdown = true, String? prompt, String? promptTitle, String? error, String? errorTitle, DataValidationErrorStyle errorStyle = DataValidationErrorStyle.stop})
A dropdown whose options are the inline values.
factory
DataValidation.listFromRange(String range, {bool allowBlank = true, bool showDropdown = true, String? prompt, String? promptTitle, String? error, String? errorTitle, DataValidationErrorStyle errorStyle = DataValidationErrorStyle.stop})
A dropdown whose options come from a cell range or defined name, e.g. '$E$1:$E$3' or 'Lists!$A$1:$A$10'.
factory
DataValidation.raw({required DataValidationType type, DataValidationOperator operator = DataValidationOperator.between, String? formula1, String? formula2, bool allowBlank = true, bool showDropdown = true, bool showErrorMessage = true, DataValidationErrorStyle errorStyle = DataValidationErrorStyle.stop, String? prompt, String? promptTitle, String? error, String? errorTitle})
Escape hatch for full control: construct any rule directly from its raw OOXML operands. Useful for date / time rules whose operands are Excel serial numbers.
factory
DataValidation.textLength({int? min, int? max, DataValidationOperator operator = DataValidationOperator.between, bool allowBlank = true, String? prompt, String? promptTitle, String? error, String? errorTitle, DataValidationErrorStyle errorStyle = DataValidationErrorStyle.stop})
Constrain the entry's character count. See DataValidation.decimal for how min / max map to the chosen operator.
factory
DataValidation.wholeNumber({int? min, int? max, DataValidationOperator operator = DataValidationOperator.between, bool allowBlank = true, String? prompt, String? promptTitle, String? error, String? errorTitle, DataValidationErrorStyle errorStyle = DataValidationErrorStyle.stop})
Allow only whole (integer) numbers. See DataValidation.decimal for how min / max map to the chosen operator.
factory

Properties

allowBlank bool
Whether an empty cell is permitted.
final
error String?
Error message body shown for an invalid entry.
final
errorStyle DataValidationErrorStyle
Severity of the message shown for an invalid entry.
final
errorTitle String?
Error message title.
final
formula1 String?
First operand. For a list this is the source, either a quoted inline list ("Low,Medium,High") or a range/defined name ($E$1:$E$3). For bounded types it is the (lower) bound; for custom it is the formula.
final
formula2 String?
Second operand, the upper bound for between / notBetween; otherwise null.
final
hashCode int
The hash code for this object.
no setteroverride
listValues List<String>?
The options of an inline list (from DataValidation.list); null for range-sourced lists or non-list rules.
no setter
operator DataValidationOperator
Comparison for bounded types. Ignored by DataValidationType.list, DataValidationType.custom and DataValidationType.none.
final
prompt String?
Input message body shown when the cell is selected.
final
promptTitle String?
Input message title.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
showDropdown bool
Whether the in-cell dropdown arrow is shown (list rules only).
final
showErrorMessage bool
Whether an invalid entry is rejected/flagged (vs. a soft, unenforced rule).
final
type DataValidationType
The rule kind.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
override

Operators

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