Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[quick_actions] Migrate to null safety #3421

Merged
merged 5 commits into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/quick_actions/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.0-nullsafety

* Migrate to null safety.

## 0.4.0+12

* Fix outdated links across a number of markdown files ([#3276](https://github.com/flutter/plugins/pull/3276))
Expand Down
15 changes: 8 additions & 7 deletions packages/quick_actions/lib/quick_actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class ShortcutItem {
///
/// Only [icon] should be nullable. It will remain `null` if unset.
const ShortcutItem({
@required this.type,
@required this.localizedTitle,
required this.type,
required this.localizedTitle,
this.icon,
});

Expand All @@ -35,7 +35,7 @@ class ShortcutItem {

/// Name of native resource (xcassets etc; NOT a Flutter asset) to be
/// displayed as the icon for this item.
final String icon;
final String? icon;
}

/// Quick actions plugin.
Expand Down Expand Up @@ -65,15 +65,16 @@ class QuickActions {
assert(call.method == 'launch');
handler(call.arguments);
});
final String action = await channel.invokeMethod<String>('getLaunchAction');
final String? action =
await channel.invokeMethod<String?>('getLaunchAction');
if (action != null) {
handler(action);
}
}

/// Sets the [ShortcutItem]s to become the app's quick actions.
Future<void> setShortcutItems(List<ShortcutItem> items) async {
final List<Map<String, String>> itemsList =
final List<Map<String, String?>> itemsList =
items.map(_serializeItem).toList();
await channel.invokeMethod<void>('setShortcutItems', itemsList);
}
Expand All @@ -82,8 +83,8 @@ class QuickActions {
Future<void> clearShortcutItems() =>
channel.invokeMethod<void>('clearShortcutItems');

Map<String, String> _serializeItem(ShortcutItem item) {
return <String, String>{
Map<String, String?> _serializeItem(ShortcutItem item) {
return <String, String?>{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ideally we'd make this non-null and omit entries that are null from the dictionary, but that would require changes to the native implementations unfortunately, so LG.

'type': item.type,
'localizedTitle': item.localizedTitle,
'icon': item.icon,
Expand Down
12 changes: 6 additions & 6 deletions packages/quick_actions/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: quick_actions
description: Flutter plugin for creating shortcuts on home screen, also known as
Quick Actions on iOS and App Shortcuts on Android.
homepage: https://github.com/flutter/plugins/tree/master/packages/quick_actions
version: 0.4.0+12
version: 0.5.0-nullsafety

flutter:
plugin:
Expand All @@ -16,17 +16,17 @@ flutter:
dependencies:
flutter:
sdk: flutter
meta: ^1.0.5
meta: ^1.3.0-nullsafety

dev_dependencies:
test: ^1.3.0
mockito: ^3.0.0
test: ^1.16.0-nullsafety
mockito: ^5.0.0-nullsafety.0
flutter_test:
sdk: flutter
integration_test:
path: ../integration_test
pedantic: ^1.8.0
pedantic: ^1.10.0-nullsafety

environment:
sdk: ">=2.1.0 <3.0.0"
sdk: ">=2.12.0-0 <3.0.0"
flutter: ">=1.12.13+hotfix.5"
2 changes: 1 addition & 1 deletion packages/quick_actions/test/quick_actions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:quick_actions/quick_actions.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();

QuickActions quickActions;
late QuickActions quickActions;
final List<MethodCall> log = <MethodCall>[];

setUp(() {
Expand Down
1 change: 1 addition & 0 deletions script/nnbd_plugins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ readonly NNBD_PLUGINS_LIST=(
"path_provider"
"package_info"
"plugin_platform_interface"
"quick_actions"
"sensors"
"share"
"shared_preferences"
Expand Down