decode<T> static method

T? decode<T>(
  1. dynamic value, [
  2. T fromJson(
    1. Map
    )?
])

Decodes an optional value from JSON maps or method channel results.

value - The value to decode (typically json[key] or a method channel result). fromJson - Optional function to decode objects. If not provided, value is cast directly.

Implementation

static T? decode<T>(dynamic value, [T Function(Map)? fromJson]) {
  if (value == null) return null;
  if (fromJson != null) {
    return fromJson(value as Map);
  }
  return value as T?;
}