Creates an extended model that is serializable based on your models.

The libraries serializable_models_rest and serializable_models_sqlite may exist to go with this.

Getting started

Add the serializable_models to your pubspec.yaml and build_runner to your dev dependencies.

Upon changes run:

flutter pub run build_runner build


  1. Your first constructor is used when needed in generated code. Make sure you create one.
  2. Your classes must be private, have a part declared, be abstract and extend SerializableModelBase
  3. If you need to change field serialization you have to change the library directly. This may change in the future

Below is the simplest example. To see more, check example/lib/models - showing models that don't have generated code, and all the options you have when generating

import 'package:serializable_models/annotations.dart';
import 'package:serializable_models/model_base.dart';

part 'item.o.dart';

abstract class _Item extends SerializableModelBase {
  int id;
  String name;

    required this.id,
    required this.name,

After running build, this results in this: lib/models/task.o.dart

// Source library: package:example/models/item.dart

part of 'item.dart';

class Item extends _Item {
  get pk => id;

    required int id,
    required String name,
  }) : super(
    id: id,
    name: name,

  factory Item.fromSerializable(Map<String, dynamic> from) {
    var instance = Item(
      id: from["id"],
      name: from["name"],

    return instance;

  Item clone() {
    return Item(
      id: id,
      name: name,

  void loadSerializable(Map<String, dynamic> from) {
    id = from["id"];
    name = from["name"];

  Map<String, dynamic> toSerializable() {
    return {
      "id": id,
      "name": name,