You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .website/quick_start.md
+172Lines changed: 172 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,3 +68,175 @@ serinus run --dev
68
68
```
69
69
70
70
This will start the server on `http://localhost:3000` in development mode allowing you to leverage on an hot-restarter to automatically restart the server when a file is changed.
71
+
72
+
## Let's complete it
73
+
74
+
So now we have the application running but we should start adding some features to see how things really work.
75
+
76
+
## Update the Todo model
77
+
78
+
The `Todo` class is already augmented with the `JsonObject` mixin, meaning that this object can be converted to its json representation by the framework. But we also need to create it directly from the body although not the `Todo` class itself so let's create a `TodoDto` class.
As you can see the `TodoDto` class has a `fromJson` factory constructor that will be used by the cli to generate the [ModelProvider](/techniques/model_provider.html). So let's do exactly that.
119
+
120
+
Let's execute this command:
121
+
122
+
```bash
123
+
serinus generate models
124
+
```
125
+
126
+
And now we have a new file `model_provider` in the root of the `lib` folder.
127
+
128
+
```dart
129
+
import 'package:serinus/serinus.dart';
130
+
131
+
import 'todo.dart';
132
+
133
+
/// The [MyProjectModelProvider] is used to provide models for the Serinus application.
134
+
/// It contains mappings for serializing and deserializing models to and from JSON.
135
+
class MyProjectModelProvider extends ModelProvider {
136
+
@override
137
+
Map<String, Function> get toJsonModels {
138
+
return {"Todo": (model) => (model as Todo).toJson()};
0 commit comments