This recipe will be divided into two components – serialization and integration. We're going to start with the serialization functions and then snap together all the pieces that we built over the last three recipes:
- Open task.dart and add an id property and a default constructor. This will allow the Task model to be transformed into a generic Model:
import 'package:flutter/foundation.dart';
import '../repositories/repository.dart';
class Task {
final int id;
String description;
bool complete;
Task({@required this.id, this.complete = false, this.description
= ''});
}
- Now, we need to add the serialization and deserialization methods. These functions will take the data from a generic Model and return a more usable strongly typed object. Add the following code immediately after the constructor.
Task.fromModel(Model model)
: id = model.id,
description = model.data['description'],
complete = model.data[&apos...