decode method

  1. @override
void decode(
  1. dynamic state
)
override

Read state from json-like object

Possible values are:

  • Base DartType - bool, int, double, string, etc.
  • List
  • Map<String, DartType> - map of objects of base dart type, list or map

Implementation

@override
void decode(state) {
  final devices = (state['devices'] as List?)?.cast<String>();
  final frame = state['frame'] as bool?;
  final orientation = state['orientation'] as String?;

  value = value.copyWith(
    devices: devices != null
        ? this
            .devices
            .where((element) => devices.contains(slugify(element.name)))
            .toList()
        : null,
    hasFrame: frame,
    orientation: orientation != null //
        ? Orientation.values.byName(orientation)
        : null,
  );

  super.decode(state);
}