LusciiSdkAction.fromMap constructor
LusciiSdkAction.fromMap(
- Map map
Creates a new LusciiSdkAction from the given map.
Implementation
factory LusciiSdkAction.fromMap(Map<dynamic, dynamic> map) {
// Assign values to explicitly typed variables
final id = map['id'] as String?;
final name = map['name'] as String?;
final icon = map['icon'] as String?;
final isLaunchable = map['isLaunchable'] as bool?;
final launchableStatus = map['launchableStatus'] as String?;
final isPlanned = map['isPlanned'] as bool?;
final isSelfCare = map['isSelfCare'] as bool?;
final isExtra = map['isExtra'] as bool?;
// Check for required fields and their types
if (id == null) {
throw ArgumentError(
"Expected 'id' to be a non-null String, but got "
// ignore: avoid_dynamic_calls
"${map['id']?.runtimeType}",
);
}
if (name == null) {
throw ArgumentError(
"Expected 'name' to be a non-null String, but got "
// ignore: avoid_dynamic_calls
"${map['name']?.runtimeType}",
);
}
if (icon == null) {
throw ArgumentError(
"Expected 'icon' to be a non-null String, but got "
// ignore: avoid_dynamic_calls
"${map['icon']?.runtimeType}",
);
}
if (isLaunchable == null) {
throw ArgumentError(
"Expected 'isLaunchable' to be a non-null bool, but got "
// ignore: avoid_dynamic_calls
"${map['isLaunchable']?.runtimeType}",
);
}
if (launchableStatus == null) {
throw ArgumentError(
"Expected 'launchableStatus' to be a non-null String, but got "
// ignore: avoid_dynamic_calls
"${map['launchableStatus']?.runtimeType}",
);
}
return LusciiSdkAction(
id: id,
name: name,
icon: icon,
completedAt: map['completedAt'] != null
? DateTime.fromMillisecondsSinceEpoch(
(map['completedAt'] as double).toInt() * 1000,
)
: null,
launchableStatus: _parseLaunchableStatus(launchableStatus),
isLaunchable: isLaunchable,
isPlanned: isPlanned,
isSelfCare: isSelfCare,
isExtra: isExtra,
);
}