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:...

March 15, 2023 · Joel Tok

Flutter Camera - An Example with Detailed Explanations and Pitfalls

Introduction Working in Flutter to build my new mobile app (now defunct) ZapCam has been an amazing experience. For those who do not know, Flutter is an open-sourced cross-platform mobile app development framework, developed by Google and written in Dart. Developing in it has been surprisingly elegant. The type system of Dart is clean and expressive, and Flutter itself offers many development tools that come prepackaged that makes development, building and deploying for device a total breeze....

October 6, 2020 · Joel Tok