JSnailParser mixin
A utility class for parsing values from dynamic sources such as Maps.
This class provides methods for safely extracting values from a source map or other dynamic objects. It includes methods for reading various data types like strings, integers, doubles, booleans, lists, maps, and enumerations.
Example:
final Map<String, dynamic> data = {
'name': 'John',
'age': 30,
'isStudent': true,
'grades': [95, 88, 75],
};
final parser = SnailParser();
final name = parser.readString(data, 'name'); // 'John'
final age = parser.readInt(data, 'age'); // 30
final isStudent = parser.readBool(data, 'isStudent'); // true
final grades = parser.readList(data, 'grades'); // [95, 88, 75]
- Mixin applications
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
hasKey(
dynamic source, dynamic key) → bool - Checks if the source contains the given key.
-
hasValue(
dynamic source, dynamic key) → bool - Checks if the source contains a non-null value for the given key.
-
isBool(
dynamic value) → bool - Checks if the given value is a boolean.
-
isDouble(
dynamic value) → bool - Checks if the given value is a double.
-
isInt(
dynamic value) → bool - Checks if the given value is an integer.
-
isList(
dynamic value) → bool - Checks if the given value is a list.
-
isMap(
dynamic value) → bool - Checks if the given value is a map.
-
isNum(
dynamic value) → bool - Checks if the given value is a numeric value (either int or double).
-
isString(
dynamic value) → bool - Checks if the given value is a string.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
readBool(
dynamic source, dynamic key, {bool defaultValue = false}) → bool -
Reads a boolean value from the source, and if not found, returns the
provided
defaultValue
. -
readDouble(
dynamic source, dynamic key, {double defaultValue = -1.0}) → double -
Reads a double value from the source, and if not found, returns the
provided
defaultValue
. -
readEnum<
T extends Enum> (dynamic source, dynamic key, List< T> values, T defaultValue) → T -
Reads an enumeration value from the source. If not found or in case of an
error, it returns the provided
defaultValue
. -
readInt(
dynamic source, dynamic key, {int defaultValue = -1}) → int -
Reads an integer value from the source, and if not found, returns the
provided
defaultValue
. -
readList(
dynamic source, dynamic key) → List - Reads a list value from the source, and if not found, returns an empty list.
-
readMap(
dynamic source, dynamic key) → Map - Reads a map value from the source, and if not found, returns an empty map.
-
readNum(
dynamic source, dynamic key, {num defaultValue = -1.0}) → num -
Reads a numeric value from the source, and if not found, returns the
provided
defaultValue
. -
readString(
dynamic source, dynamic key, {String defaultValue = ''}) → String -
Reads a string value from the source, and if not found, returns the
provided
defaultValue
. -
readValue(
dynamic source, dynamic key) → Object? -
Reads a value from the source, returning it if the source is a map,
or
null
otherwise. -
toString(
) → String -
A string representation of this object.
inherited
-
tryReadBool(
dynamic source, dynamic key) → bool? -
Tries to read a boolean value from the source. If the value is not a
boolean, it returns
null
. -
tryReadDouble(
dynamic source, dynamic key) → double? -
Tries to read a double value from the source. If the value is not a
double, it returns
null
. -
tryReadEnum<
T extends Enum> (dynamic source, dynamic key, List< T> values) → T? -
Tries to read an enumeration value from the source. If the value is a
string that matches one of the provided
values
, it returns the corresponding enumeration value. If not found or in case of an error, it returnsnull
. -
tryReadInt(
dynamic source, dynamic key) → int? -
Tries to read an integer value from the source. If the value is not an
integer, it returns
null
. -
tryReadList(
dynamic source, dynamic key) → List? -
Tries to read a list value from the source. If the value is not a list,
it returns
null
. -
tryReadMap(
dynamic source, dynamic key) → Map? -
Tries to read a map value from the source. If the value is not a map,
it returns
null
. -
tryReadNum(
dynamic source, dynamic key) → num? -
Tries to read a numeric value from the source. If the value is not a
number, it returns
null
. -
tryReadString(
dynamic source, dynamic key) → String? -
Tries to read a string value from the source. If the value is not a
string, it returns
null
.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited