ModelLess class

The ModelLess class is a dynamic, flexible data structure designed to handle nested data structures and perform common operations such as accessing, setting, and manipulating data within the structure. This class is particularly useful in scenarios where you need to work with JSON-like data structures that may contain nested maps or lists. Below is a detailed breakdown of the key features and methods in the ModelLess class.

Constructors

ModelLess({Map<String, dynamic>? fields, dynamic onGet(dynamic value)?})
ModelLess.fromDynamic(dynamic val)
factory
ModelLess.fromJson(String jsonString)
making a new model from a json string
factory
ModelLess.fromMap(Map map)
making a new model from a map
factory

Properties

fields Map<String, dynamic>
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
onGet ↔ dynamic Function(dynamic value)?
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

get<T>(String key, {T? def}) → T
Retrieves a value of type T associated with the specified key. If the key contains '/', it treats the key as a path and navigates through the nested structure to retrieve the value. If the key does not exist, returns the provided default value def. Supports basic types such as int, String, bool, List, and DateTime. key The key or path whose associated value is to be retrieved. def A default value of type T that is returned if the key does not exist. Returns the value associated with the key, or the default value if the key does not exist.
getByPath<T>(List path, {dynamic def}) → T
Retrieves a value of type T from the model 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 T that is returned if the path cannot be resolved. Returns the value of type T at the specified path, or the default value if the path cannot be resolved.
getByPathString<T>(String path, {dynamic def}) → T
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 T that is returned if the path cannot be resolved. Returns the value of type T at the specified path, or the default value if the path cannot be resolved. For example, the path is a String path for access to a node. for example "posts/news/1/title"
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
remove(String key) → void
Removes a key-value pair from the model based on the provided key. If the key does not exist, the method does nothing. key The key of the key-value pair to be removed.
set(String key, dynamic value) → void
add or set a new node to the model
toMap() Map<String, dynamic>
Converts the ModelLess instance to a Map<String, dynamic>. Each key-value pair in the fields map is added to the resulting map. If a value is of type DateTime, it is converted to a string representation. Returns a map representation of the ModelLess instance.
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited
operator [](String key) Object?
Retrieves the value associated with the specified key. If the key does not exist, returns an empty string. If an onGet callback is defined, it is invoked with the retrieved value before returning it. key The key whose associated value is to be retrieved. Returns the value associated with the key, or an empty string if the key does not exist.
operator []=(String key, dynamic value) → void
Sets the value for the specified key in the model. If the key already exists, its value is updated. If the key does not exist, a new key-value pair is added to the model. key The key for which the value is to be set. value The value to be associated with the key.

Static Methods

toListMap(List<ModelLess> list) List<Map<String, dynamic>>
Converts a list of ModelLess instances to a list of maps. Each ModelLess instance in the input list is converted to a map using the toMap method, and the resulting maps are collected into a new list. list The list of ModelLess instances to be converted. Returns a list of maps, where each map corresponds to a ModelLess instance.