Skip to content

Commit 43883bd

Browse files
committed
Upgrade to Flutter 2 & null safety
1 parent 5b7fae8 commit 43883bd

21 files changed

+422
-388
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## master
2+
3+
* Change all `void ... async` methods to `Future<void> ... async` so that callers can use `await`.
4+
15
## v9.1.9 (2021-05-11)
26

37
* Adds support for overriding the replies notification string values through `repliesNotificationTeamName`, `repliesNotificationReplyButton`, `repliesNotificationDismissButton`
@@ -6,7 +10,6 @@
610
## v9.1.8 (2021-02-17)
711

812
* Fixes an issue with iOS invocation events causing the welcome message not to show.
9-
* Change all `void ... async` methods to `Future<void> ... async` so that callers can use `await`.
1013

1114
## v9.1.7 (2020-10-01)
1215

analysis_options.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,9 @@ linter:
4848
- always_put_control_body_on_new_line
4949
# - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219
5050
- always_require_non_null_named_parameters
51-
- always_specify_types
51+
# - always_specify_types
5252
- annotate_overrides
5353
# - avoid_annotating_with_dynamic # conflicts with always_specify_types
54-
- avoid_as
5554
# - avoid_bool_literals_in_conditional_expressions # not yet tested
5655
# - avoid_catches_without_on_clauses # we do this commonly
5756
# - avoid_catching_errors # we do this commonly

example/lib/main.dart

Lines changed: 136 additions & 120 deletions
Large diffs are not rendered by default.

example/pubspec.yaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: InstabugSample
1+
name: instabug_sample
22
description: A new Flutter project.
33

44
# The following line prevents the package from being accidentally published to
@@ -26,11 +26,6 @@ dependencies:
2626
instabug_flutter:
2727
path: ../
2828

29-
30-
# The following adds the Cupertino Icons font to your application.
31-
# Use with the CupertinoIcons class for iOS style icons.
32-
cupertino_icons: ^1.0.0
33-
3429
dev_dependencies:
3530
flutter_test:
3631
sdk: flutter

example/test/widget_test.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
import 'package:flutter/material.dart';
99
import 'package:flutter_test/flutter_test.dart';
10-
11-
import 'package:InstabugSample/main.dart';
10+
import 'package:instabug_sample/main.dart';
1211

1312
void main() {
1413
testWidgets('Counter increments smoke test', (WidgetTester tester) async {

lib/BugReporting.dart

Lines changed: 29 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore_for_file: avoid_classes_with_only_static_members
2+
13
import 'dart:async';
24
import 'dart:io' show Platform;
35

@@ -22,24 +24,22 @@ enum ExtendedBugReportMode {
2224
}
2325

2426
class BugReporting {
25-
static Function _onInvokeCallback;
26-
static Function _onDismissCallback;
27+
static Function? _onInvokeCallback;
28+
static Function? _onDismissCallback;
2729
static const MethodChannel _channel = MethodChannel('instabug_flutter');
2830

29-
static Future<String> get platformVersion async {
30-
final String version = await _channel.invokeMethod('getPlatformVersion');
31-
return version;
32-
}
31+
static Future<String> get platformVersion async =>
32+
(await _channel.invokeMethod<String>('getPlatformVersion'))!;
3333

3434
static Future<dynamic> _handleMethod(MethodCall call) async {
3535
switch (call.method) {
3636
case 'onInvokeCallback':
37-
_onInvokeCallback();
37+
_onInvokeCallback?.call();
3838
return;
3939
case 'onDismissCallback':
4040
final Map<dynamic, dynamic> map = call.arguments;
41-
DismissType dismissType;
42-
ReportType reportType;
41+
DismissType? dismissType;
42+
ReportType? reportType;
4343
final String dismissTypeString = map['dismissType'].toUpperCase();
4444
switch (dismissTypeString) {
4545
case 'CANCEL':
@@ -65,9 +65,9 @@ class BugReporting {
6565
break;
6666
}
6767
try {
68-
_onDismissCallback(dismissType, reportType);
68+
_onDismissCallback?.call(dismissType, reportType);
6969
} catch (exception) {
70-
_onDismissCallback();
70+
_onDismissCallback?.call();
7171
}
7272
return;
7373
}
@@ -104,14 +104,11 @@ class BugReporting {
104104
/// Default is set by `Instabug.startWithToken`.
105105
/// [invocationEvents] invocationEvent List of events that invokes the
106106
static Future<void> setInvocationEvents(
107-
List<InvocationEvent> invocationEvents) async {
108-
final List<String> invocationEventsStrings = <String>[];
109-
if (invocationEvents != null) {
110-
invocationEvents.forEach((e) {
111-
invocationEventsStrings.add(e.toString());
112-
});
113-
}
114-
final List<dynamic> params = <dynamic>[invocationEventsStrings];
107+
List<InvocationEvent>? invocationEvents) async {
108+
final invocationEventsStrings =
109+
invocationEvents?.map((e) => e.toString()).toList(growable: false) ??
110+
[];
111+
final params = <dynamic>[invocationEventsStrings];
115112
await _channel.invokeMethod<Object>('setInvocationEvents:', params);
116113
}
117114

@@ -137,14 +134,10 @@ class BugReporting {
137134

138135
///Sets what type of reports, bug or feedback, should be invoked.
139136
/// [reportTypes] - List of reportTypes
140-
static Future<void> setReportTypes(List<ReportType> reportTypes) async {
141-
final List<String> reportTypesStrings = <String>[];
142-
if (reportTypes != null) {
143-
reportTypes.forEach((e) {
144-
reportTypesStrings.add(e.toString());
145-
});
146-
}
147-
final List<dynamic> params = <dynamic>[reportTypesStrings];
137+
static Future<void> setReportTypes(List<ReportType>? reportTypes) async {
138+
final reportTypesStrings =
139+
reportTypes?.map((e) => e.toString()).toList(growable: false) ?? [];
140+
final params = <dynamic>[reportTypesStrings];
148141
await _channel.invokeMethod<Object>('setReportTypes:', params);
149142
}
150143

@@ -161,28 +154,22 @@ class BugReporting {
161154
/// Default is set by `Instabug.startWithToken`.
162155
/// [invocationOptions] List of invocation options
163156
static Future<void> setInvocationOptions(
164-
List<InvocationOption> invocationOptions) async {
165-
final List<String> invocationOptionsStrings = <String>[];
166-
if (invocationOptions != null) {
167-
invocationOptions.forEach((e) {
168-
invocationOptionsStrings.add(e.toString());
169-
});
170-
}
171-
final List<dynamic> params = <dynamic>[invocationOptionsStrings];
157+
List<InvocationOption>? invocationOptions) async {
158+
final invocationOptionsStrings =
159+
invocationOptions?.map((e) => e.toString()).toList(growable: false) ??
160+
[];
161+
final params = <dynamic>[invocationOptionsStrings];
172162
await _channel.invokeMethod<Object>('setInvocationOptions:', params);
173163
}
174164

175165
/// Invoke bug reporting with report type and options.
176166
/// [reportType] type
177167
/// [invocationOptions] List of invocation options
178168
static Future<void> show(
179-
ReportType reportType, List<InvocationOption> invocationOptions) async {
180-
final List<String> invocationOptionsStrings = <String>[];
181-
if (invocationOptions != null) {
182-
invocationOptions.forEach((e) {
183-
invocationOptionsStrings.add(e.toString());
184-
});
185-
}
169+
ReportType reportType, List<InvocationOption>? invocationOptions) async {
170+
final invocationOptionsStrings =
171+
invocationOptions?.map((e) => e.toString()).toList(growable: false) ??
172+
[];
186173
final List<dynamic> params = <dynamic>[
187174
reportType.toString(),
188175
invocationOptionsStrings

lib/Chats.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1+
// ignore_for_file: avoid_classes_with_only_static_members
2+
13
import 'dart:async';
24

35
import 'package:flutter/services.dart';
46

57
class Chats {
68
static const MethodChannel _channel = MethodChannel('instabug_flutter');
79

8-
static Future<String> get platformVersion async {
9-
final String version = await _channel.invokeMethod('getPlatformVersion');
10-
return version;
11-
}
10+
static Future<String> get platformVersion async =>
11+
(await _channel.invokeMethod<String>('getPlatformVersion'))!;
1212

1313
@deprecated
1414

1515
///Use {@link BugReporting.show} instead.
1616
///Manual invocation for chats view.
17-
static Future<void> show() async {
18-
await _channel.invokeMethod<Object>('showChats');
19-
}
17+
static Future<void> show() async =>
18+
await _channel.invokeMethod<Object>('showChats');
2019

2120
@deprecated
2221

lib/CrashReporting.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
// ignore_for_file: avoid_classes_with_only_static_members
2+
13
import 'dart:async';
24
import 'dart:convert';
3-
import 'dart:io' show Platform, exit;
5+
import 'dart:io' show Platform;
46

57
import 'package:flutter/foundation.dart';
68
import 'package:flutter/services.dart';
@@ -11,10 +13,8 @@ import 'package:stack_trace/stack_trace.dart';
1113
class CrashReporting {
1214
static const MethodChannel _channel = MethodChannel('instabug_flutter');
1315
static bool enabled = true;
14-
static Future<String> get platformVersion async {
15-
final String version = await _channel.invokeMethod('getPlatformVersion');
16-
return version;
17-
}
16+
static Future<String> get platformVersion async =>
17+
(await _channel.invokeMethod<String>('getPlatformVersion'))!;
1818

1919
///Enables and disables Enables and disables automatic crash reporting.
2020
/// [boolean] isEnabled
@@ -37,7 +37,7 @@ class CrashReporting {
3737
/// [dynamic] exception
3838
/// [StackTrace] stack
3939
static Future<void> reportHandledCrash(dynamic exception,
40-
[StackTrace stack]) async {
40+
[StackTrace? stack]) async {
4141
if (stack != null) {
4242
_sendCrash(exception, stack, true);
4343
} else {
@@ -57,9 +57,9 @@ class CrashReporting {
5757
for (int i = 0; i < trace.frames.length; i++) {
5858
frames.add(ExceptionData(
5959
trace.frames[i].uri.toString(),
60-
trace.frames[i].member,
61-
trace.frames[i].line,
62-
trace.frames[i].column == null ? 0 : trace.frames[i].column));
60+
trace.frames[i].member!,
61+
trace.frames[i].line!,
62+
trace.frames[i].column == null ? 0 : trace.frames[i].column!));
6363
}
6464
final CrashData crashData = CrashData(
6565
exception.toString(), Platform.operatingSystem.toString(), frames);

lib/FeatureRequests.dart

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore_for_file: avoid_classes_with_only_static_members
2+
13
import 'dart:async';
24

35
import 'package:flutter/services.dart';
@@ -7,10 +9,8 @@ enum ActionType { requestNewFeature, addCommentToFeature }
79
class FeatureRequests {
810
static const MethodChannel _channel = MethodChannel('instabug_flutter');
911

10-
static Future<String> get platformVersion async {
11-
final String version = await _channel.invokeMethod('getPlatformVersion');
12-
return version;
13-
}
12+
static Future<String> get platformVersion async =>
13+
(await _channel.invokeMethod<String>('getPlatformVersion'))!;
1414

1515
///Shows the UI for feature requests list
1616
static Future<void> show() async {
@@ -23,17 +23,10 @@ class FeatureRequests {
2323
/// field is required or not.
2424
/// [actionTypes] An enum that indicates which action types will have the isEmailFieldRequired
2525
static Future<void> setEmailFieldRequired(
26-
bool isEmailFieldRequired, List<ActionType> actionTypes) async {
27-
final List<String> actionTypesStrings = <String>[];
28-
if (actionTypes != null) {
29-
actionTypes.forEach((e) {
30-
actionTypesStrings.add(e.toString());
31-
});
32-
}
33-
final List<dynamic> params = <dynamic>[
34-
isEmailFieldRequired,
35-
actionTypesStrings
36-
];
26+
bool isEmailFieldRequired, List<ActionType>? actionTypes) async {
27+
final actionTypesStrings =
28+
actionTypes?.map((e) => e.toString()).toList(growable: false) ?? [];
29+
final params = <dynamic>[isEmailFieldRequired, actionTypesStrings];
3730
await _channel.invokeMethod<Object>(
3831
'setEmailFieldRequiredForFeatureRequests:forAction:', params);
3932
}

lib/Instabug.dart

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore_for_file: avoid_classes_with_only_static_members
2+
13
import 'dart:async';
24
import 'dart:io' show Platform;
35
import 'dart:typed_data';
@@ -88,10 +90,8 @@ enum ReproStepsMode { enabled, disabled, enabledWithNoScreenshots }
8890
class Instabug {
8991
static const MethodChannel _channel = MethodChannel('instabug_flutter');
9092

91-
static Future<String> get platformVersion async {
92-
final String version = await _channel.invokeMethod('getPlatformVersion');
93-
return version;
94-
}
93+
static Future<String> get platformVersion async =>
94+
(await _channel.invokeMethod<String>('getPlatformVersion'))!;
9595

9696
/// Starts the SDK.
9797
/// This is the main SDK method that does all the magic. This is the only
@@ -102,10 +102,8 @@ class Instabug {
102102
/// the SDK's UI.
103103
static Future<void> start(
104104
String token, List<InvocationEvent> invocationEvents) async {
105-
final List<String> invocationEventsStrings = <String>[];
106-
invocationEvents.forEach((e) {
107-
invocationEventsStrings.add(e.toString());
108-
});
105+
final List<String> invocationEventsStrings =
106+
invocationEvents.map((e) => e.toString()).toList(growable: false);
109107
final List<dynamic> params = <dynamic>[token, invocationEventsStrings];
110108
await _channel.invokeMethod<Object>(
111109
'startWithToken:invocationEvents:', params);
@@ -123,7 +121,7 @@ class Instabug {
123121
/// and set the user's [name] to be included with all reports.
124122
/// It also reset the chats on device to that email and removes user attributes,
125123
/// user data and completed surveys.
126-
static Future<void> identifyUser(String email, [String name]) async {
124+
static Future<void> identifyUser(String email, [String? name]) async {
127125
final List<dynamic> params = <dynamic>[email, name];
128126
await _channel.invokeMethod<Object>('identifyUserWithEmail:name:', params);
129127
}
@@ -162,9 +160,9 @@ class Instabug {
162160
}
163161

164162
/// Gets all tags of reported feedback, bug or crash. Returns the list of tags.
165-
static Future<List<String>> getTags() async {
166-
final List<dynamic> tags = await _channel.invokeMethod<Object>('getTags');
167-
return tags != null ? tags.cast<String>() : null;
163+
static Future<List<String>?> getTags() async {
164+
final tags = await _channel.invokeMethod<List<dynamic>>('getTags');
165+
return tags?.cast<String>();
168166
}
169167

170168
/// Add custom user attribute [value] with a [key] that is going to be sent with each feedback, bug or crash.
@@ -181,16 +179,16 @@ class Instabug {
181179
}
182180

183181
/// Returns the user attribute associated with a given [key].
184-
static Future<String> getUserAttributeForKey(String key) async {
182+
static Future<String?> getUserAttributeForKey(String key) async {
185183
final List<dynamic> params = <dynamic>[key];
186-
return await _channel.invokeMethod<Object>(
184+
return await _channel.invokeMethod<String>(
187185
'getUserAttributeForKey:', params);
188186
}
189187

190188
/// A new Map containing all the currently set user attributes, or an empty Map if no user attributes have been set.
191189
static Future<Map<String, String>> getUserAttributes() async {
192-
final Object userAttributes =
193-
await _channel.invokeMethod<Object>('getUserAttributes');
190+
final userAttributes =
191+
await _channel.invokeMethod<Map<dynamic, dynamic>>('getUserAttributes');
194192
return userAttributes != null
195193
? Map<String, String>.from(userAttributes)
196194
: <String, String>{};

lib/InstabugLog.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
// ignore_for_file: avoid_classes_with_only_static_members
2+
13
import 'dart:async';
24

35
import 'package:flutter/services.dart';
46

57
class InstabugLog {
68
static const MethodChannel _channel = MethodChannel('instabug_flutter');
79

8-
static Future<String> get platformVersion async {
9-
final String version = await _channel.invokeMethod('getPlatformVersion');
10-
return version;
11-
}
10+
static Future<String> get platformVersion async =>
11+
(await _channel.invokeMethod<String>('getPlatformVersion'))!;
1212

1313
/// Appends a log [message] to Instabug internal log
1414
/// These logs are then sent along the next uploaded report.

0 commit comments

Comments
 (0)