Skip to content

Commit 812628d

Browse files
committed
migrated to null safety
1 parent b21494e commit 812628d

File tree

11 files changed

+38
-50
lines changed

11 files changed

+38
-50
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
## 0.0.1
1+
## 1.0.0
22

3-
* TODO: Describe initial release.
3+
* Initial Development Release

example/lib/main.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@ class MyApp extends StatefulWidget {
1313
class _MyAppState extends State<MyApp> {
1414
String action = 'No Action';
1515
final FlutterShortcuts flutterShortcuts = FlutterShortcuts();
16-
int maxLimit;
16+
int? maxLimit;
1717

1818
@override
1919
void initState() {
2020
super.initState();
2121
flutterShortcuts.initialize((String incomingAction) {
2222
setState(() {
23-
if (incomingAction != null) {
24-
action = incomingAction;
25-
}
23+
action = incomingAction;
2624
});
2725
});
2826
}
@@ -59,7 +57,7 @@ class _MyAppState extends State<MyApp> {
5957
ElevatedButton(
6058
child: Text("Get Max Shortcut Limit"),
6159
onPressed: () async {
62-
int result =
60+
int? result =
6361
await flutterShortcuts.getMaxShortcutLimit();
6462
setState(() {
6563
maxLimit = result;

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ packages:
6868
path: ".."
6969
relative: true
7070
source: path
71-
version: "0.0.1"
71+
version: "1.0.0"
7272
flutter_test:
7373
dependency: "direct dev"
7474
description: flutter

example/pubspec.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ description: Demonstrates how to use the flutter_shortcuts plugin.
33

44
# The following line prevents the package from being accidentally published to
55
# pub.dev using `pub publish`. This is preferred for private packages.
6-
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
6+
publish_to: "none" # Remove this line if you wish to publish to pub.dev
77

88
environment:
9-
sdk: ">=2.7.0 <3.0.0"
9+
sdk: ">=2.12.0 <3.0.0"
1010

1111
dependencies:
1212
flutter:
@@ -33,7 +33,6 @@ dev_dependencies:
3333

3434
# The following section is specific to Flutter.
3535
flutter:
36-
3736
# The following line ensures that the Material Icons font is
3837
# included with your application, so that you can use the icons in
3938
# the material Icons class.

example/test/widget_test.dart

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,5 @@ void main() {
1414
testWidgets('Verify Platform version', (WidgetTester tester) async {
1515
// Build our app and trigger a frame.
1616
await tester.pumpWidget(MyApp());
17-
18-
// Verify that platform version is retrieved.
19-
expect(
20-
find.byWidgetPredicate(
21-
(Widget widget) => widget is Text &&
22-
widget.data.startsWith('Running on:'),
23-
),
24-
findsOneWidget,
25-
);
2617
});
2718
}

lib/flutter_shortcuts.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class FlutterShortcuts {
2323

2424
/// [getMaxShortcutLimit] returns the maximum number of static or dynamic
2525
/// shortcuts that each launcher icon can have at a time.
26-
Future<int> getMaxShortcutLimit() {
26+
Future<int?> getMaxShortcutLimit() {
2727
return FlutterShortcutsPlatform.instance.getMaxShortcutLimit();
2828
}
2929

@@ -35,7 +35,7 @@ class FlutterShortcuts {
3535

3636
/// [setShortcutItems] will set all the shortcut items.
3737
Future<void> setShortcutItems(
38-
{List<FlutterShortcutItem> shortcutItems}) async {
38+
{required List<FlutterShortcutItem> shortcutItems}) async {
3939
return FlutterShortcutsPlatform.instance.setShortcutItems(shortcutItems);
4040
}
4141

@@ -47,28 +47,28 @@ class FlutterShortcuts {
4747
/// [pushShortcutItem] will push a new shortcut item.
4848
/// If there is already a dynamic or pinned shortcut with the same ID,
4949
/// the shortcut will be updated and pushed at the end of the shortcut list.
50-
Future<void> pushShortcutItem({FlutterShortcutItem shortcut}) async {
50+
Future<void> pushShortcutItem({required FlutterShortcutItem shortcut}) async {
5151
return FlutterShortcutsPlatform.instance.pushShortcutItem(shortcut);
5252
}
5353

5454
/// [addShortcutItems] updates dynamic or pinned shortcuts with same IDs
5555
/// and pushes new shortcuts with different IDs.
5656
Future<void> pushShortcutItems(
57-
{List<FlutterShortcutItem> shortcutList}) async {
57+
{required List<FlutterShortcutItem> shortcutList}) async {
5858
return FlutterShortcutsPlatform.instance.pushShortcutItems(shortcutList);
5959
}
6060

6161
/// [updateShortcutItems] updates shortcut items.
6262
/// If the IDs of the shortcuts are not same, no changes will be reflected.
6363
Future<void> updateShortcutItems(
64-
{List<FlutterShortcutItem> shortcutList}) async {
64+
{required List<FlutterShortcutItem> shortcutList}) async {
6565
return FlutterShortcutsPlatform.instance.updateShortcutItems(shortcutList);
6666
}
6767

6868
/// [updateShortcutItem] updates a single shortcut item based on id.
6969
/// If the ID of the shortcut is not same, no changes will be reflected.
7070
Future<void> updateShortcutItem(
71-
{String id, FlutterShortcutItem shortcut}) async {
71+
{required String id, required FlutterShortcutItem shortcut}) async {
7272
return FlutterShortcutsPlatform.instance.updateShortcutItem(id, shortcut);
7373
}
7474

@@ -86,7 +86,8 @@ class FlutterShortcuts {
8686

8787
/// [changeShortcutItemIcon] will change the icon of the shortcut based on id.
8888
/// If the ID of the shortcut is not same, no changes will be reflected.
89-
Future<void> changeShortcutItemIcon({String id, String icon}) async {
89+
Future<void> changeShortcutItemIcon(
90+
{required String id, required String icon}) async {
9091
return FlutterShortcutsPlatform.instance.changeShortcutItemIcon(id, icon);
9192
}
9293
}

lib/src/helper/model/flutter_shortcut_item.dart

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ for more details.
88
99
*/
1010

11-
import 'package:flutter/material.dart';
12-
1311
class FlutterShortcutItem {
1412
const FlutterShortcutItem({
15-
@required this.id,
16-
@required this.action,
17-
@required this.shortLabel,
13+
required this.id,
14+
required this.action,
15+
required this.shortLabel,
1816
this.longLabel,
1917
this.icon,
2018
});
@@ -29,8 +27,8 @@ class FlutterShortcutItem {
2927
final String shortLabel;
3028

3129
// Long label of the shortcut
32-
final String longLabel;
30+
final String? longLabel;
3331

3432
// Icon of the shortcut
35-
final String icon;
33+
final String? icon;
3634
}

lib/src/method_call/flutter_shortcuts_method_call_handler.dart

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@ class FlutterShortcutsMethodCallHandler extends FlutterShortcutsPlatform {
2424
assert(call.method == 'launch');
2525
actionHandler(call.arguments);
2626
});
27-
final String action = await channel.invokeMethod<String>('getLaunchAction');
27+
final String? action =
28+
await channel.invokeMethod<String>('getLaunchAction');
2829
if (action != null) {
2930
actionHandler(action);
3031
}
3132
}
3233

3334
@override
34-
Future<int> getMaxShortcutLimit() {
35+
Future<int?> getMaxShortcutLimit() {
3536
return channel.invokeMethod<int>('getMaxShortcutLimit');
3637
}
3738

@@ -46,7 +47,7 @@ class FlutterShortcutsMethodCallHandler extends FlutterShortcutsPlatform {
4647

4748
@override
4849
Future<void> setShortcutItems(List<FlutterShortcutItem> items) async {
49-
final List<Map<String, String>> itemsList =
50+
final List<Map<String, String?>> itemsList =
5051
items.map(_serializeItem).toList();
5152
await channel.invokeMethod<void>('setShortcutItems', itemsList);
5253
}
@@ -58,28 +59,28 @@ class FlutterShortcutsMethodCallHandler extends FlutterShortcutsPlatform {
5859

5960
@override
6061
Future<void> pushShortcutItem(FlutterShortcutItem shortcut) async {
61-
final Map<String, String> item = _serializeItem(shortcut);
62+
final Map<String, String?> item = _serializeItem(shortcut);
6263
await channel.invokeMethod<void>('pushShortcutItem', [item]);
6364
}
6465

6566
@override
6667
Future<void> pushShortcutItems(List<FlutterShortcutItem> items) async {
67-
final List<Map<String, String>> itemsList =
68+
final List<Map<String, String?>> itemsList =
6869
items.map(_serializeItem).toList();
6970
await channel.invokeMethod<void>('pushShortcutItems', itemsList);
7071
}
7172

7273
@override
7374
Future<void> updateShortcutItems(List<FlutterShortcutItem> items) async {
74-
final List<Map<String, String>> itemsList =
75+
final List<Map<String, String?>> itemsList =
7576
items.map(_serializeItem).toList();
7677
await channel.invokeMethod<void>('updateShortcutItems', itemsList);
7778
}
7879

7980
@override
8081
Future<void> updateShortcutItem(
8182
String id, FlutterShortcutItem shortcut) async {
82-
final Map<String, String> item = _serializeItem(shortcut);
83+
final Map<String, String?> item = _serializeItem(shortcut);
8384
await channel.invokeMethod<void>('updateShortcutItem', [item]);
8485
}
8586

@@ -99,8 +100,8 @@ class FlutterShortcutsMethodCallHandler extends FlutterShortcutsPlatform {
99100
await channel.invokeMethod<void>('changeShortcutItemIcon', [id, icon]);
100101
}
101102

102-
Map<String, String> _serializeItem(FlutterShortcutItem item) {
103-
return <String, String>{
103+
Map<String, String?> _serializeItem(FlutterShortcutItem item) {
104+
return <String, String?>{
104105
'id': item.id,
105106
'action': item.action,
106107
'shortLabel': item.shortLabel,

lib/src/platform/flutter_shortcuts_platform.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ abstract class FlutterShortcutsPlatform extends PlatformInterface {
3232
throw UnimplementedError("initialize() has not been implemented.");
3333
}
3434

35-
Future<int> getMaxShortcutLimit() {
35+
Future<int?> getMaxShortcutLimit() {
3636
throw UnimplementedError("getMaxShortcutLimit() has not been implemented.");
3737
}
3838

pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,5 +157,5 @@ packages:
157157
source: hosted
158158
version: "2.1.0"
159159
sdks:
160-
dart: ">=2.12.0-0.0 <3.0.0"
160+
dart: ">=2.12.0 <3.0.0"
161161
flutter: ">=1.20.0"

0 commit comments

Comments
 (0)