Skip to content

Commit f8a53a5

Browse files
authored
[android_intent] Migrate to nnbd (flutter#3328)
1 parent 88466ff commit f8a53a5

File tree

5 files changed

+29
-24
lines changed

5 files changed

+29
-24
lines changed

packages/android_intent/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.0-nullsafety
2+
3+
* Migrate to null safety.
4+
15
## 0.3.7+8
26

37
* Update Flutter SDK constraint.

packages/android_intent/lib/android_intent.dart

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class AndroidIntent {
3636
this.arguments,
3737
this.package,
3838
this.componentName,
39-
Platform platform,
39+
Platform? platform,
4040
this.type,
4141
}) : assert(action != null || componentName != null,
4242
'action or component (or both) must be specified'),
@@ -47,8 +47,8 @@ class AndroidIntent {
4747
/// app code, it may break without warning.
4848
@visibleForTesting
4949
AndroidIntent.private({
50-
@required Platform platform,
51-
@required MethodChannel channel,
50+
required Platform platform,
51+
required MethodChannel channel,
5252
this.action,
5353
this.flags,
5454
this.category,
@@ -66,47 +66,47 @@ class AndroidIntent {
6666
/// includes constants like `ACTION_VIEW`.
6767
///
6868
/// See https://developer.android.com/reference/android/content/Intent.html#intent-structure.
69-
final String action;
69+
final String? action;
7070

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

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

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

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

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

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

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

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

149-
return await _channel.invokeMethod<bool>(
149+
final result = await _channel.invokeMethod<bool>(
150150
'canResolveActivity',
151151
_buildArguments(),
152152
);
153+
return result!;
153154
}
154155

155156
/// Constructs the map of arguments which is passed to the plugin.
156157
Map<String, dynamic> _buildArguments() {
157158
return {
158159
if (action != null) 'action': action,
159-
if (flags != null) 'flags': convertFlags(flags),
160+
if (flags != null) 'flags': convertFlags(flags!),
160161
if (category != null) 'category': category,
161162
if (data != null) 'data': data,
162163
if (arguments != null) 'arguments': arguments,

packages/android_intent/pubspec.yaml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
name: android_intent
22
description: Flutter plugin for launching Android Intents. Not supported on iOS.
33
homepage: https://github.com/flutter/plugins/tree/master/packages/android_intent
4-
# 0.3.y+z is compatible with 1.0.0, if you land a breaking change bump
5-
# the version to 2.0.0.
6-
# See more details: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0
7-
version: 0.3.7+8
4+
version: 2.0.0-nullsafety
85

96
flutter:
107
plugin:
@@ -16,15 +13,15 @@ flutter:
1613
dependencies:
1714
flutter:
1815
sdk: flutter
19-
platform: ">=2.0.0 <4.0.0"
20-
meta: ^1.0.5
16+
platform: ^3.0.0-nullsafety.4
17+
meta: ^1.3.0-nullsafety.6
2118
dev_dependencies:
22-
test: ^1.3.0
23-
mockito: ^3.0.0
19+
test: ^1.16.0-nullsafety.13
20+
mockito: ^4.1.3
2421
flutter_test:
2522
sdk: flutter
26-
pedantic: ^1.8.0
23+
pedantic: ^1.10.0-nullsafety.1
2724

2825
environment:
29-
sdk: ">=2.3.0 <3.0.0"
26+
sdk: ">=2.12.0-0 <3.0.0"
3027
flutter: ">=1.12.13+hotfix.5"

packages/android_intent/test/android_intent_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ import 'package:platform/platform.dart';
1111

1212
void main() {
1313
AndroidIntent androidIntent;
14-
MockMethodChannel mockChannel;
14+
late MockMethodChannel mockChannel;
1515
setUp(() {
1616
mockChannel = MockMethodChannel();
17+
when(mockChannel.invokeMethod<bool>('canResolveActivity', any))
18+
.thenAnswer((realInvocation) async => true);
1719
});
1820

1921
group('AndroidIntent', () {

script/nnbd_plugins.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# null-safe is available on stable.
66

77
readonly NNBD_PLUGINS_LIST=(
8+
"android_intent"
89
"connectivity"
910
"device_info"
1011
"flutter_plugin_android_lifecycle"

0 commit comments

Comments
 (0)