maybeFromDynamic static method

JsonRowBuilderModel? maybeFromDynamic(
  1. dynamic map, {
  2. Map<String, dynamic> args = const {},
  3. JsonWidgetRegistry? registry,
})

Implementation

static JsonRowBuilderModel? maybeFromDynamic(
  dynamic map, {
  Map<String, dynamic> args = const {},
  JsonWidgetRegistry? registry,
}) {
  JsonRowBuilderModel? result;

  if (map != null) {
    if (map is String) {
      map = yaon.parse(
        map,
        normalize: true,
      );
    }

    if (map is JsonRowBuilderModel) {
      result = map;
    } else {
      registry ??= JsonWidgetRegistry.instance;
      map = registry.processArgs(map, <String>{}).value;
      result = JsonRowBuilderModel(
        args,
        crossAxisAlignment: () {
          dynamic parsed = ThemeDecoder.decodeCrossAxisAlignment(
            map['crossAxisAlignment'],
            validate: false,
          );
          parsed ??= CrossAxisAlignment.center;

          return parsed;
        }(),
        mainAxisAlignment: () {
          dynamic parsed = ThemeDecoder.decodeMainAxisAlignment(
            map['mainAxisAlignment'],
            validate: false,
          );
          parsed ??= MainAxisAlignment.start;

          return parsed;
        }(),
        mainAxisSize: () {
          dynamic parsed = ThemeDecoder.decodeMainAxisSize(
            map['mainAxisSize'],
            validate: false,
          );
          parsed ??= MainAxisSize.max;

          return parsed;
        }(),
        textBaseline: () {
          dynamic parsed = ThemeDecoder.decodeTextBaseline(
            map['textBaseline'],
            validate: false,
          );

          return parsed;
        }(),
        textDirection: () {
          dynamic parsed = ThemeDecoder.decodeTextDirection(
            map['textDirection'],
            validate: false,
          );

          return parsed;
        }(),
        verticalDirection: () {
          dynamic parsed = ThemeDecoder.decodeVerticalDirection(
            map['verticalDirection'],
            validate: false,
          );
          parsed ??= VerticalDirection.down;

          return parsed;
        }(),
        children: () {
          dynamic parsed = JsonWidgetData.maybeFromDynamicList(
            map['children'],
            registry: registry,
          );
          parsed ??= const <JsonWidgetData>[];

          return parsed;
        }(),
      );
    }
  }

  return result;
}