-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathtutorial_model.dart
More file actions
85 lines (72 loc) · 1.85 KB
/
tutorial_model.dart
File metadata and controls
85 lines (72 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2025 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:jaspr/jaspr.dart';
class TutorialModel {
const TutorialModel({
required this.title,
required this.url,
required this.units,
});
final String title;
final String url;
final List<TutorialUnit> units;
@decoder
factory TutorialModel.fromMap(Map<Object?, Object?> json) {
return TutorialModel(
title: json['title'] as String,
url: json['url'] as String,
units: (json['units'] as List<Object?>)
.map((e) => TutorialUnit.fromMap(e as Map<Object?, Object?>))
.toList(),
);
}
@encoder
Map<Object?, Object?> toJson() => {
'title': title,
'url': url,
'units': units.map((e) => e.toJson()).toList(),
};
}
class TutorialUnit {
const TutorialUnit({
required this.title,
required this.chapters,
});
final String title;
final List<TutorialChapter> chapters;
@decoder
factory TutorialUnit.fromMap(Map<Object?, Object?> json) {
return TutorialUnit(
title: json['title'] as String,
chapters: (json['chapters'] as List<Object?>)
.map((e) => TutorialChapter.fromMap(e as Map<Object?, Object?>))
.toList(),
);
}
@encoder
Map<Object?, Object?> toJson() => {
'title': title,
'chapters': chapters.map((e) => e.toJson()).toList(),
};
}
class TutorialChapter {
const TutorialChapter({
required this.title,
required this.url,
});
final String title;
final String url;
@decoder
factory TutorialChapter.fromMap(Map<Object?, Object?> json) {
return TutorialChapter(
title: json['title'] as String,
url: json['url'] as String,
);
}
@encoder
Map<Object?, Object?> toJson() => {
'title': title,
'url': url,
};
}