decode static method

NapaWidget? decode(
  1. dynamic data
)

Deserialize a json compatible object into a NapaWidget or null.

Implementation

static NapaWidget? decode(dynamic data) {
  if (data is Map<String, dynamic>) {
    String name = '';
    try {
      try {
        name = data['_name'];
      } catch (ex) {
        throw Exception('_name property not found.');
      }
      final decodeRegister = _register[name];
      if (decodeRegister != null) {
        return decodeRegister(data);
      } else {
        throw Exception('Unknown implementation for widget \'$name\'');
      }
    } on _NapaException catch (ex) {
      throw _NapaException('Exception decoding widget \'$name\'\n$ex');
    }
  }

  return null;
}