navigation<T> method
T
navigation<T>({
Navigates through the map using the provided path and retrieves a value of type T
.
path
: A string representing the navigation path, using '/' to separate keys or indices (for lists).
def
: A default value of type T
that is returned if the path does not resolve to a valid value.
Example:
var map = {
'user': {
'name': 'John',
'address': {
'city': 'New York',
'zip': '10001'
}
}
};
var city = map.navigation(path: 'user/address/city', def: 'Unknown'); // returns 'New York'
var zip = map.navigation(path: 'user/address/zip', def: '00000'); // returns '10001'
var country = map.navigation(path: 'user/address/country', def: 'USA'); // returns 'USA'
Implementation
T navigation<T>({
required String path,
required T def,
}) {
List<String> arrPath = path.split('/');
return _navigationArray(
map: this,
pathArray: arrPath,
def: def,
);
}