FormCollection class

A collection of form options that can be used with various form field widgets.

FormCollection provides a unified interface for handling different types of option data structures including flat arrays, key-value maps, and structured objects. It automatically converts various input formats into a consistent FormOption list.

Supported input formats:

  • List<String>: Simple string arrays
  • Map<String, String>: Key-value pairs
  • List<Map<String, dynamic>>: Structured option objects

Example usage:

// From array
final options1 = FormCollection.from(['Option 1', 'Option 2']);

// From map
final options2 = FormCollection.from({'key1': 'Label 1', 'key2': 'Label 2'});

// From structured list
final options3 = FormCollection.fromKeyValue([
  {'value': 'us', 'label': 'United States'},
  {'value': 'ca', 'label': 'Canada'}
]);

Constructors

FormCollection.empty()
Creates an empty FormCollection with no options.
const
FormCollection.from(dynamic data)
Creates a FormCollection from dynamic input data with automatic structure detection.
factory
FormCollection.fromArray(List<String> data)
Creates a FormCollection from a flat array of strings.
factory
FormCollection.fromKeyValue(List<Map<String, dynamic>> data)
Creates a FormCollection from a list of structured option maps.
factory
FormCollection.fromMap(Map<String, String> data)
Creates a FormCollection from a map of key-value pairs.
factory

Properties

first → FormOption
no setter
hashCode → int
The hash code for this object.
no setteroverride
isArrayStructure → bool
Returns true if this collection was created from a flat array structure.
no setter
isEmpty → bool
Returns true if this collection contains no options.
no setter
isKeyValueStructure → bool
Returns true if this collection was created from key-value structured data.
no setter
isNotEmpty → bool
Returns true if this collection contains at least one option.
no setter
iterator → Iterator<FormOption>
no setter
labels → List<String>
no setter
last → FormOption
no setter
length → int
Returns the total number of options in this collection.
no setter
options → List<FormOption>
Returns an immutable list of all options in this collection.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
values → List<String>
no setter

Methods

containsLabel(String label) → bool
containsValue(String value) → bool
filter(bool test(FormOption)) → FormCollection
getByLabel(String label) → FormOption?
getByValue(String value) → FormOption?
getLabelByValue(String value) → String?
getValueByLabel(String label) → String?
indexOfLabel(String label) → int
indexOfValue(String value) → int
isValidValue(String? value) → bool
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
searchByLabel(String query) → List<FormOption>
sort([int compare(FormOption, FormOption)?]) → FormCollection
toKeyValueList() → List<Map<String, dynamic>>
toMap() → Map<String, String>
toString() → String
A string representation of this object.
override
validateValue(String? value, {String? errorMessage}) → String?

Operators

operator ==(Object other) → bool
The equality operator.
override
operator [](int index) → FormOption?
Accesses a FormOption at the specified index.