AppwinInitResult.fromMap constructor

AppwinInitResult.fromMap(
  1. Map<Object?, Object?>? map
)

Parses what the native side sends over the method channel.

An unknown string maps to AppwinInitStatus.unknown rather than throwing: a Dart package is often older than the native SDK it talks to, and a value it has never heard of must not crash the host app.

Implementation

factory AppwinInitResult.fromMap(Map<Object?, Object?>? map) {
  final status = switch (map?['status']) {
    'ready' => AppwinInitStatus.ready,
    'unavailable' => AppwinInitStatus.unavailable,
    'notConfigured' => AppwinInitStatus.notConfigured,
    _ => AppwinInitStatus.unknown,
  };
  final reason = switch (map?['reason']) {
    'plan' => AppwinUnavailableReason.plan,
    'disabled' => AppwinUnavailableReason.disabled,
    _ => null,
  };
  return AppwinInitResult(status, reason: reason);
}