ModelLessArray<T> class

The ModelLessArray class is a generic class that provides a structure for managing a collection of items, specifically designed to work with ModelLess objects. This class offers features such as accessing items by index, dynamically setting and getting values, parsing JSON into the array, and retrieving nested data using paths. Below is an explanation and breakdown of the key features:

Constructors

ModelLessArray({List<T>? fields})

Properties

fields List<T>?
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
isEmpty bool
no setter
isNotEmpty bool
no setter
length int
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addAll(ModelLessArray<T> value) → void
Adds all elements from another ModelLessArray to this array. If the fields list is null, it initializes it before adding the elements. value The ModelLessArray whose elements are to be added to this array.
clear() → void
Clears all elements from the array. If the fields list is null, it initializes it before clearing. After calling this method, the array will be empty.
forEach<R>(T function(R val)) → void
Iterates over each element in the array and applies the provided function. The function takes an element of type R as input and returns a value of type T. function A function that takes an element of type R and returns a value of type T. Example:
get<T>(int index, {dynamic def}) → T
getByPath<R>(List path, {dynamic def}) → R
Retrieves a value of type R from the array using a specified path. The path is a list of keys and/or indices that navigate through nested ModelLess or ModelLessArray structures. If the path cannot be fully resolved, the method returns the provided default value. path A list of keys and/or indices representing the navigation path. def A default value of type R that is returned if the path
getByPathString<R>(String path, {dynamic def}) → R
Retrieves a value of type R from the array using a string path. The path is a '/'-separated string that navigates through nested ModelLess or ModelLessArray structures. If the path cannot be fully resolved, the method returns the provided default value. path A '/'-separated string representing the navigation path. def A default value of type R that is returned if the path
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
set(dynamic value) → void
Adds a value to the end of the array. If the fields list is null, it initializes it before adding the value. value The value to add to the array.
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited
operator [](int index) → dynamic
operator []=(int index, T value) → void
Sets the value at the specified index in the array. If the index is out of range, an exception is thrown. index The index at which to set the value. value The value to set at the specified index. Example:

Static Methods

fromJson<T>(String jsonString) ModelLessArray<T>
Creates a ModelLessArray from a JSON string. The JSON string should represent a list of objects. Each object in the list is converted to a ModelLess instance and added to the array. If parsing fails, an error message is logged to the console. jsonString The JSON string to parse. Returns a ModelLessArray containing the parsed ModelLess instances.
fromList(List list) ModelLessArray
Creates a ModelLessArray from a List. Each element in the list is added to the ModelLessArray. If an element is a Map, it is converted to a ModelLess instance before being added. list The List to convert into a ModelLessArray. Returns a ModelLessArray containing the elements from the list.
tryJson<T>(String jsonString) ModelLessArray<T>?
Attempts to create a ModelLessArray from a JSON string. The JSON string should represent a list of objects. Each object in the list is converted to a ModelLess instance and added to the array. If parsing fails, the method returns null. jsonString The JSON string to parse. Returns a ModelLessArray containing the parsed ModelLess instances, or null if parsing fails