Skip to content

Commit

Permalink
Fix latent type error in Flutter manifest (flutter#20143)
Browse files Browse the repository at this point in the history
  • Loading branch information
mravn-google authored Aug 2, 2018
1 parent 8380e20 commit 651c5ab
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 12 deletions.
43 changes: 32 additions & 11 deletions packages/flutter_tools/lib/src/flutter_manifest.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,16 @@ class FlutterManifest {
/// Returns an empty manifest.
static FlutterManifest empty() {
final FlutterManifest manifest = new FlutterManifest._();
manifest._descriptor = <String, dynamic>{};
manifest._flutterDescriptor = <String, dynamic>{};
manifest._descriptor = const <String, dynamic>{};
manifest._flutterDescriptor = const <String, dynamic>{};
return manifest;
}

/// Returns a mock manifest with the given contents.
static FlutterManifest mock(Map<String, dynamic> contents) {
final FlutterManifest manifest = new FlutterManifest._();
manifest._descriptor = contents ?? const <String, dynamic>{};
manifest._flutterDescriptor = manifest._descriptor['flutter'] ?? const <String, dynamic>{};
return manifest;
}

Expand Down Expand Up @@ -108,22 +116,35 @@ class FlutterManifest {
return _flutterDescriptor['uses-material-design'] ?? false;
}

/// Properties defining how to expose this Flutter project as a module
/// for integration into an unspecified host app.
YamlMap get moduleDescriptor {
return _flutterDescriptor.containsKey('module')
? _flutterDescriptor['module'] ?? const <String, dynamic>{}
: null;
}

/// True if this manifest declares a Flutter module project.
///
/// A Flutter project is considered a module when it has a `module:`
/// descriptor. A Flutter module project supports integration into an
/// existing host app.
///
/// Such a project can be created using `flutter create -t module`.
bool get isModule => moduleDescriptor != null;
bool get isModule => _flutterDescriptor.containsKey('module');

/// True if this manifest declares a Flutter plugin project.
///
/// A Flutter project is considered a plugin when it has a `plugin:`
/// descriptor. A Flutter plugin project wraps custom Android and/or
/// iOS code in a Dart interface for consumption by other Flutter app
/// projects.
///
/// Such a project can be created using `flutter create -t plugin`.
bool get isPlugin => _flutterDescriptor.containsKey('plugin');

/// Returns the Android package declared by this manifest in its
/// module or plugin descriptor. Returns null, if there is no
/// such declaration.
String get androidPackage {
if (isModule)
return _flutterDescriptor['module']['androidPackage'];
if (isPlugin)
return _flutterDescriptor['plugin']['androidPackage'];
return null;
}

List<Map<String, dynamic>> get fontsDescriptor {
final List<dynamic> fontList = _flutterDescriptor['fonts'];
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/src/project.dart
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class AndroidModuleProject {
template.render(
directory,
<String, dynamic>{
'androidIdentifier': project.manifest.moduleDescriptor['androidPackage'],
'androidIdentifier': project.manifest.androidPackage,
},
printStatusWhenWriting: false,
);
Expand Down
27 changes: 27 additions & 0 deletions packages/flutter_tools/test/flutter_manifest_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,33 @@ flutter:
''';
final FlutterManifest flutterManifest = await FlutterManifest.createFromString(manifest);
expect(flutterManifest.isEmpty, false);
expect(flutterManifest.isModule, false);
expect(flutterManifest.isPlugin, false);
expect(flutterManifest.androidPackage, null);
});

test('allows a module declaration', () async {
const String manifest = '''
name: test
flutter:
module:
androidPackage: com.example
''';
final FlutterManifest flutterManifest = await FlutterManifest.createFromString(manifest);
expect(flutterManifest.isModule, true);
expect(flutterManifest.androidPackage, 'com.example');
});

test('allows a plugin declaration', () async {
const String manifest = '''
name: test
flutter:
plugin:
androidPackage: com.example
''';
final FlutterManifest flutterManifest = await FlutterManifest.createFromString(manifest);
expect(flutterManifest.isPlugin, true);
expect(flutterManifest.androidPackage, 'com.example');
});

Future<void> checkManifestVersion({
Expand Down

0 comments on commit 651c5ab

Please sign in to comment.