-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Expand file tree
/
Copy pathtutorial_layout.dart
More file actions
54 lines (44 loc) · 1.44 KB
/
tutorial_layout.dart
File metadata and controls
54 lines (44 loc) · 1.44 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
// 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';
import 'package:jaspr_content/jaspr_content.dart';
import '../models/tutorial_model.dart';
import 'doc_layout.dart';
class TutorialLayout extends DocLayout {
const TutorialLayout();
@override
String get name => 'tutorial';
@override
bool get allowBreadcrumbs => false;
@override
List<String> get defaultBodyClasses => [];
@override
Component buildBody(Page page, Component child) {
final model = switch (page.data['tutorial']) {
final Map<Object?, Object?>? tutorialData when tutorialData != null =>
TutorialModel.fromMap(tutorialData),
_ => throw Exception('No tutorial data found.'),
};
final navigationEntries = <Map<String, Object?>>[];
for (final unit in model.units) {
navigationEntries.add({'type': 'divider', 'title': unit.title});
for (final chapter in unit.chapters) {
navigationEntries.add({'title': chapter.title, 'path': chapter.url});
}
}
return super.buildBody(
page..apply(
data: {
'page': {
'showBanner': false,
'navigationCollectionTitle': model.title,
'navigationCollectionUrl': model.url,
'navigationEntries': navigationEntries,
},
},
),
child,
);
}
}