-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Expand file tree
/
Copy pathlearning_resource_model.dart
More file actions
108 lines (96 loc) · 3.33 KB
/
learning_resource_model.dart
File metadata and controls
108 lines (96 loc) · 3.33 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// 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:universal_web/web.dart' as web;
final class LearningResource {
LearningResource({
required this.name,
required this.description,
required this.type,
required this.tags,
this.link,
this.imageUrl,
});
/// Creates a [LearningResource] from a Map, used on the server
/// when parsing the yaml data files.
factory LearningResource.fromMap(Map<String, Object?> map) {
return LearningResource(
name: map['name'] as String,
description: map['description'] as String,
type: map['type'] as String,
tags: (map['tags'] as List<Object?>?)?.cast<String>() ?? [],
link: (
label: (map['link'] as Map<String, Object?>)['label'] as String,
url: (map['link'] as Map<String, Object?>)['url'] as String,
),
imageUrl: map['imageUrl'] as String?,
);
}
/// Creates a [LearningResource] from a DOM Element, used on the client
/// for recreating and filtering existing resources.
factory LearningResource.fromElement(web.Element element) {
final dataType = element.getAttribute('data-type') ?? '';
final dataTags = element.getAttribute('data-tags') ?? '';
final dataDescription = element.getAttribute('data-description') ?? '';
return LearningResource(
name: element.id,
type: dataType,
tags: dataTags.split(',').map((t) => t.trim().toLowerCase()).toList(),
description: dataDescription,
);
}
final String name;
final String description;
final String type;
final List<String> tags;
final ({String url, String label})? link;
final String? imageUrl;
}
enum LearningResourceType {
tutorial('Tutorial', ['codelab', 'tutorial']),
sampleCode('Sample code', ['quickstart', 'demo', 'sample', 'sample code']),
workshop('Workshop', ['workshop', 'video']),
recipe('Recipe', ['recipe', 'how to', 'cookbook']);
const LearningResourceType(this.label, this.tags);
final String label;
final List<String> tags;
}
enum LearningResourceTag {
ai('AI', ['ai', 'gemini', 'llm']),
animation('Animation', ['animations', 'animate', 'animation']),
architecture('Architecture', [
'state-management',
'architecture',
'provider',
'bloc',
'stream',
]),
cupertino('Cupertino', ['cupertino', 'ios', 'macos']),
design('Design', ['design', 'widgets']),
desktop('Desktop', ['windows', 'macos', 'linux']),
firebase('Firebase', ['firebase', 'firestore', 'cloud']),
goodForBeginners('Good for beginners', ['beginner', 'beginners']),
googleApis('Google APIs', ['google', 'gemini', 'maps', 'firebase', 'cloud']),
ios('iOS', ['cupertino', 'ios']),
layout('Layout', ['layout', 'lists', 'scrolling', 'widgets']),
material('Material', ['material', 'android']),
routingAndNavigation('Routing and navigation', [
'routing',
'route',
'navigation',
'navigator',
]),
stateManagement('State management', [
'state-management',
'architecture',
'provider',
'bloc',
'stream',
]),
testing('Testing', ['testing', 'tests', 'test', 'perf', 'performance']),
web('Web', ['web', 'wasm']),
widgets('Widgets', ['widgets', 'layout']);
const LearningResourceTag(this.label, this.tags);
final String label;
final List<String> tags;
}