Dart – Implementing a Factory Constructor for an Abstract Class
Problem Let’s say we want to implement a factory constructor in an abstract class. For example, given the abstract class Position, we want to enforce that all classes that implement it have two capabilities: Position.fromJson and toJson. Notice that the first of these is usually implemented as a factory constructor. We can show this in the example code below: abstract class Position { factory Position.fromJson(Map<String, dynamic> json); Map<String, dynamic> toJson(); } Unfortunately, the above will throw either one of the following errors:...