SnapshotDecoder constructor

SnapshotDecoder()

Create a new, unsealed SnapshotDecoder containing the default converters

Additional converters can be registered with SnapshotDecoder.register and SnapshotDecoder.registerWithFormat. Before being able to use this SnapshotDecoder, you'll need to seal it by calling SnapshotDecoder.seal.

Implementation

SnapshotDecoder() {
  register<String, DateTime>((v) => DateTime.parse(v));
  register<num, DateTime>(
      (v) => DateTime.fromMicrosecondsSinceEpoch((v * 1000).toInt()),
      format: 'epoch');
  register<String, Uri>((v) => Uri.parse(v));
  register<String, int>(
      (v, {String? format}) =>
          int.parse(v, radix: int.parse(format!.substring('radix:'.length))),
      format: RegExp(r'radix:(\d+)'));
  register<String, int>((v) => int.parse(v), format: 'string');
  register<String, double>((v) => double.parse(v), format: 'string');
  register<String, num>((v) => num.parse(v), format: 'string');
  register<String, DateTime>((v, {String? format}) {
    var f = DateFormat(format!);
    return f.parse(v);
  }, format: RegExp('.*'));
}