decode method

Future<T?> decode(
  1. PlatformDataProvider dataProvider,
  2. PlatformFormat format
)

Decodes the data from platform representation. Returns null if decoding failed.

Important: When implementing custom decoder it is necessary to request all data from dataProvider before awaiting on anything. Default implementation simply attempts to cast to target format.

Implementation

//
/// Default implementation simply attempts to cast to target format.
Future<T?> decode(
    PlatformDataProvider dataProvider, PlatformFormat format) async {
  final value = await dataProvider.getData(format);
  return value is T ? value : null;
}