Skip to content

Commit

Permalink
[android_intent] Migrate to nnbd (flutter#3328)
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmetf committed Dec 15, 2020
1 parent 88466ff commit f8a53a5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 24 deletions.
4 changes: 4 additions & 0 deletions packages/android_intent/CHANGELOG.md
@@ -1,3 +1,7 @@
## 2.0.0-nullsafety

* Migrate to null safety.

## 0.3.7+8

* Update Flutter SDK constraint.
Expand Down
27 changes: 14 additions & 13 deletions packages/android_intent/lib/android_intent.dart
Expand Up @@ -36,7 +36,7 @@ class AndroidIntent {
this.arguments,
this.package,
this.componentName,
Platform platform,
Platform? platform,
this.type,
}) : assert(action != null || componentName != null,
'action or component (or both) must be specified'),
Expand All @@ -47,8 +47,8 @@ class AndroidIntent {
/// app code, it may break without warning.
@visibleForTesting
AndroidIntent.private({
@required Platform platform,
@required MethodChannel channel,
required Platform platform,
required MethodChannel channel,
this.action,
this.flags,
this.category,
Expand All @@ -66,47 +66,47 @@ class AndroidIntent {
/// includes constants like `ACTION_VIEW`.
///
/// See https://developer.android.com/reference/android/content/Intent.html#intent-structure.
final String action;
final String? action;

/// Constants that can be set on an intent to tweak how it is finally handled.
/// Some of the constants are mirrored to Dart via [Flag].
///
/// See https://developer.android.com/reference/android/content/Intent.html#setFlags(int).
final List<int> flags;
final List<int>? flags;

/// An optional additional constant qualifying the given [action].
///
/// See https://developer.android.com/reference/android/content/Intent.html#intent-structure.
final String category;
final String? category;

/// The Uri that the [action] is pointed towards.
///
/// See https://developer.android.com/reference/android/content/Intent.html#intent-structure.
final String data;
final String? data;

/// The equivalent of `extras`, a generic `Bundle` of data that the Intent can
/// carry. This is a slot for extraneous data that the listener may use.
///
/// See https://developer.android.com/reference/android/content/Intent.html#intent-structure.
final Map<String, dynamic> arguments;
final Map<String, dynamic>? arguments;

/// Sets the [data] to only resolve within this given package.
///
/// See https://developer.android.com/reference/android/content/Intent.html#setPackage(java.lang.String).
final String package;
final String? package;

/// Set the exact `ComponentName` that should handle the intent. If this is
/// set [package] should also be non-null.
///
/// See https://developer.android.com/reference/android/content/Intent.html#setComponent(android.content.ComponentName).
final String componentName;
final String? componentName;
final MethodChannel _channel;
final Platform _platform;

/// Set an explicit MIME data type.
///
/// See https://developer.android.com/reference/android/content/Intent.html#intent-structure.
final String type;
final String? type;

bool _isPowerOfTwo(int x) {
/* First x in the below expression is for the case when x is 0 */
Expand Down Expand Up @@ -146,17 +146,18 @@ class AndroidIntent {
return false;
}

return await _channel.invokeMethod<bool>(
final result = await _channel.invokeMethod<bool>(
'canResolveActivity',
_buildArguments(),
);
return result!;
}

/// Constructs the map of arguments which is passed to the plugin.
Map<String, dynamic> _buildArguments() {
return {
if (action != null) 'action': action,
if (flags != null) 'flags': convertFlags(flags),
if (flags != null) 'flags': convertFlags(flags!),
if (category != null) 'category': category,
if (data != null) 'data': data,
if (arguments != null) 'arguments': arguments,
Expand Down
17 changes: 7 additions & 10 deletions packages/android_intent/pubspec.yaml
@@ -1,10 +1,7 @@
name: android_intent
description: Flutter plugin for launching Android Intents. Not supported on iOS.
homepage: https://github.com/flutter/plugins/tree/master/packages/android_intent
# 0.3.y+z is compatible with 1.0.0, if you land a breaking change bump
# the version to 2.0.0.
# See more details: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0
version: 0.3.7+8
version: 2.0.0-nullsafety

flutter:
plugin:
Expand All @@ -16,15 +13,15 @@ flutter:
dependencies:
flutter:
sdk: flutter
platform: ">=2.0.0 <4.0.0"
meta: ^1.0.5
platform: ^3.0.0-nullsafety.4
meta: ^1.3.0-nullsafety.6
dev_dependencies:
test: ^1.3.0
mockito: ^3.0.0
test: ^1.16.0-nullsafety.13
mockito: ^4.1.3
flutter_test:
sdk: flutter
pedantic: ^1.8.0
pedantic: ^1.10.0-nullsafety.1

environment:
sdk: ">=2.3.0 <3.0.0"
sdk: ">=2.12.0-0 <3.0.0"
flutter: ">=1.12.13+hotfix.5"
4 changes: 3 additions & 1 deletion packages/android_intent/test/android_intent_test.dart
Expand Up @@ -11,9 +11,11 @@ import 'package:platform/platform.dart';

void main() {
AndroidIntent androidIntent;
MockMethodChannel mockChannel;
late MockMethodChannel mockChannel;
setUp(() {
mockChannel = MockMethodChannel();
when(mockChannel.invokeMethod<bool>('canResolveActivity', any))
.thenAnswer((realInvocation) async => true);
});

group('AndroidIntent', () {
Expand Down
1 change: 1 addition & 0 deletions script/nnbd_plugins.sh
Expand Up @@ -5,6 +5,7 @@
# null-safe is available on stable.

readonly NNBD_PLUGINS_LIST=(
"android_intent"
"connectivity"
"device_info"
"flutter_plugin_android_lifecycle"
Expand Down

0 comments on commit f8a53a5

Please sign in to comment.