2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
4
5
+ import 'flutter_manifest.dart' ;
5
6
import 'project.dart' ;
6
7
import 'project_validator_result.dart' ;
7
8
@@ -11,7 +12,100 @@ abstract class ProjectValidator {
11
12
/// Can return more than one result in case a file/command have a lot of info to share to the user
12
13
Future <List <ProjectValidatorResult >> start (FlutterProject project);
13
14
/// new ProjectValidators should be added here for the ValidateProjectCommand to run
14
- static const List < ProjectValidator > allProjectValidators = < ProjectValidator > [
15
- // TODO(jasguerrero): add validators
15
+ static List < ProjectValidator > allProjectValidators = < ProjectValidator > [
16
+ GeneralInfoProjectValidator (),
16
17
];
17
18
}
19
+
20
+ /// Validator run for all platforms that extract information from the pubspec.yaml.
21
+ ///
22
+ /// Specific info from different platforms should be written in their own ProjectValidator.
23
+ class GeneralInfoProjectValidator extends ProjectValidator {
24
+ @override
25
+ Future <List <ProjectValidatorResult >> start (FlutterProject project) async {
26
+ final FlutterManifest flutterManifest = project.manifest;
27
+ final List <ProjectValidatorResult > result = < ProjectValidatorResult > [];
28
+ final ProjectValidatorResult appNameValidatorResult = _getAppNameResult (flutterManifest);
29
+ result.add (appNameValidatorResult);
30
+ final String supportedPlatforms = _getSupportedPlatforms (project);
31
+ if (supportedPlatforms.isEmpty) {
32
+ return result;
33
+ }
34
+ final ProjectValidatorResult supportedPlatformsResult = ProjectValidatorResult (
35
+ name: 'Supported Platforms' ,
36
+ value: supportedPlatforms,
37
+ status: StatusProjectValidator .success
38
+ );
39
+ final ProjectValidatorResult isFlutterPackage = _isFlutterPackageValidatorResult (flutterManifest);
40
+ result.addAll (< ProjectValidatorResult > [supportedPlatformsResult, isFlutterPackage]);
41
+ if (flutterManifest.flutterDescriptor.isNotEmpty) {
42
+ result.add (_materialDesignResult (flutterManifest));
43
+ result.add (_pluginValidatorResult (flutterManifest));
44
+ }
45
+ return result;
46
+ }
47
+
48
+ ProjectValidatorResult _getAppNameResult (FlutterManifest flutterManifest) {
49
+ final String appName = flutterManifest.appName;
50
+ const String name = 'App Name' ;
51
+ if (appName.isEmpty) {
52
+ return const ProjectValidatorResult (
53
+ name: name,
54
+ value: 'name not found' ,
55
+ status: StatusProjectValidator .error
56
+ );
57
+ }
58
+ return ProjectValidatorResult (
59
+ name: name,
60
+ value: appName,
61
+ status: StatusProjectValidator .success
62
+ );
63
+ }
64
+
65
+ ProjectValidatorResult _isFlutterPackageValidatorResult (FlutterManifest flutterManifest) {
66
+ final String value;
67
+ final StatusProjectValidator status;
68
+ if (flutterManifest.flutterDescriptor.isNotEmpty) {
69
+ value = 'yes' ;
70
+ status = StatusProjectValidator .success;
71
+ } else {
72
+ value = 'no' ;
73
+ status = StatusProjectValidator .warning;
74
+ }
75
+
76
+ return ProjectValidatorResult (
77
+ name: 'Is Flutter Package' ,
78
+ value: value,
79
+ status: status
80
+ );
81
+ }
82
+
83
+ ProjectValidatorResult _materialDesignResult (FlutterManifest flutterManifest) {
84
+ return ProjectValidatorResult (
85
+ name: 'Uses Material Design' ,
86
+ value: flutterManifest.usesMaterialDesign? 'yes' : 'no' ,
87
+ status: StatusProjectValidator .success
88
+ );
89
+ }
90
+
91
+ String _getSupportedPlatforms (FlutterProject project) {
92
+ return project.getSupportedPlatforms ().map ((SupportedPlatform platform) => platform.name).join (', ' );
93
+ }
94
+
95
+ ProjectValidatorResult _pluginValidatorResult (FlutterManifest flutterManifest) {
96
+ return ProjectValidatorResult (
97
+ name: 'Is Plugin' ,
98
+ value: flutterManifest.isPlugin? 'yes' : 'no' ,
99
+ status: StatusProjectValidator .success
100
+ );
101
+ }
102
+
103
+ @override
104
+ bool supportsProject (FlutterProject project) {
105
+ // this validator will run for any type of project
106
+ return true ;
107
+ }
108
+
109
+ @override
110
+ String get title => 'General Info' ;
111
+ }
0 commit comments