6

Ideally I'm looking for something like :

typedef Json = Map<String, dynamic>;

From what I understand, this language feature is under review typedef for simple type aliases with ETA Q1'19

But for a immediate alternative, what would be the simplest way to "extend" a Map in Dart ? All the solutions I could find are quite old and look overkill. At the end I just want an alias for my Map.

Thanks in advance.

datto
  • 391
  • 2
  • 13
  • 4
    If you really don't want to wait, you could make your own class that wraps an existing `Map` and implements just the methods you need. If you need your class to actually be a `Map` type, you can do `class MyMap with MapMixin implements Map`. – jamesdlin May 04 '19 at 14:44
  • 1
    This feature is being implemented and tracked here: https://github.com/dart-lang/language/issues/65 – Andre Pena Jun 13 '20 at 09:40

1 Answers1

1

Dart 2.13

  1. Update analysis_options.yaml
analyzer:
  enable-experiment:
    - nonfunction-type-aliases
  1. Run
flutter run --enable-experiment=nonfunction-type-aliases
  • More info https://stackoverflow.com/questions/66847006/how-do-i-use-type-aliases-typedefs-also-non-function-in-dart – user697576 Nov 14 '21 at 17:12