Skip to content

Commit 5a5c53d

Browse files
author
Ali Abdelfattah
authored
Merge pull request #180 from guykogus/nnbd
Dart 2 & null safety
2 parents 14629fd + 1f2f4e5 commit 5a5c53d

24 files changed

+1040
-684
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
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`

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 {

ios/Classes/InstabugFlutterPlugin.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
3939
const char *type = [signature methodReturnType];
4040

4141
if (strcmp(type, "v") != 0) {
42-
void *returnVal;
42+
void *returnVal;
4343
[inv getReturnValue:&returnVal];
4444
NSObject *resultSet = (__bridge NSObject *)returnVal;
4545
result(resultSet);
46+
} else {
47+
result(nil);
4648
}
4749
}
4850
if (!isImplemented) {

lib/BugReporting.dart

Lines changed: 44 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
// ignore_for_file: avoid_classes_with_only_static_members
2+
13
import 'dart:async';
24
import 'dart:io' show Platform;
5+
36
import 'package:flutter/services.dart';
47
import 'package:instabug_flutter/Instabug.dart';
58

@@ -21,24 +24,22 @@ enum ExtendedBugReportMode {
2124
}
2225

2326
class BugReporting {
24-
static Function _onInvokeCallback;
25-
static Function _onDismissCallback;
27+
static Function? _onInvokeCallback;
28+
static Function? _onDismissCallback;
2629
static const MethodChannel _channel = MethodChannel('instabug_flutter');
2730

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

3334
static Future<dynamic> _handleMethod(MethodCall call) async {
3435
switch (call.method) {
3536
case 'onInvokeCallback':
36-
_onInvokeCallback();
37+
_onInvokeCallback?.call();
3738
return;
3839
case 'onDismissCallback':
3940
final Map<dynamic, dynamic> map = call.arguments;
40-
DismissType dismissType;
41-
ReportType reportType;
41+
DismissType? dismissType;
42+
ReportType? reportType;
4243
final String dismissTypeString = map['dismissType'].toUpperCase();
4344
switch (dismissTypeString) {
4445
case 'CANCEL':
@@ -64,17 +65,17 @@ class BugReporting {
6465
break;
6566
}
6667
try {
67-
_onDismissCallback(dismissType, reportType);
68+
_onDismissCallback?.call(dismissType, reportType);
6869
} catch (exception) {
69-
_onDismissCallback();
70+
_onDismissCallback?.call();
7071
}
7172
return;
7273
}
7374
}
7475

7576
///Enables and disables manual invocation and prompt options for bug and feedback.
7677
/// [boolean] isEnabled
77-
static void setEnabled(bool isEnabled) async {
78+
static Future<void> setEnabled(bool isEnabled) async {
7879
final List<dynamic> params = <dynamic>[isEnabled];
7980
await _channel.invokeMethod<Object>('setBugReportingEnabled:', params);
8081
}
@@ -83,7 +84,7 @@ class BugReporting {
8384
/// This block is executed on the UI thread. Could be used for performing any
8485
/// UI changes before the SDK's UI is shown.
8586
/// [function] A callback that gets executed before invoking the SDK
86-
static void setOnInvokeCallback(Function function) async {
87+
static Future<void> setOnInvokeCallback(Function function) async {
8788
_channel.setMethodCallHandler(_handleMethod);
8889
_onInvokeCallback = function;
8990
await _channel.invokeMethod<Object>('setOnInvokeCallback');
@@ -93,7 +94,7 @@ class BugReporting {
9394
/// This block is executed on the UI thread. Could be used for performing any
9495
/// UI changes before the SDK's UI is shown.
9596
/// [function] A callback that gets executed before invoking the SDK
96-
static void setOnDismissCallback(Function function) async {
97+
static Future<void> setOnDismissCallback(Function function) async {
9798
_channel.setMethodCallHandler(_handleMethod);
9899
_onDismissCallback = function;
99100
await _channel.invokeMethod<Object>('setOnDismissCallback');
@@ -102,15 +103,12 @@ class BugReporting {
102103
/// Sets the events that invoke the feedback form.
103104
/// Default is set by `Instabug.startWithToken`.
104105
/// [invocationEvents] invocationEvent List of events that invokes the
105-
static void setInvocationEvents(
106-
List<InvocationEvent> invocationEvents) async {
107-
final List<String> invocationEventsStrings = <String>[];
108-
if (invocationEvents != null) {
109-
invocationEvents.forEach((e) {
110-
invocationEventsStrings.add(e.toString());
111-
});
112-
}
113-
final List<dynamic> params = <dynamic>[invocationEventsStrings];
106+
static Future<void> setInvocationEvents(
107+
List<InvocationEvent>? invocationEvents) async {
108+
final invocationEventsStrings =
109+
invocationEvents?.map((e) => e.toString()).toList(growable: false) ??
110+
[];
111+
final params = <dynamic>[invocationEventsStrings];
114112
await _channel.invokeMethod<Object>('setInvocationEvents:', params);
115113
}
116114

@@ -121,8 +119,8 @@ class BugReporting {
121119
/// attachments. In iOS 10+,NSPhotoLibraryUsageDescription should be set in
122120
/// info.plist to enable gallery image attachments.
123121
/// [screenRecording] A boolean to enable or disable screen recording attachments.
124-
static void setEnabledAttachmentTypes(bool screenshot, bool extraScreenshot,
125-
bool galleryImage, bool screenRecording) async {
122+
static Future<void> setEnabledAttachmentTypes(bool screenshot,
123+
bool extraScreenshot, bool galleryImage, bool screenRecording) async {
126124
final List<dynamic> params = <dynamic>[
127125
screenshot,
128126
extraScreenshot,
@@ -136,21 +134,17 @@ class BugReporting {
136134

137135
///Sets what type of reports, bug or feedback, should be invoked.
138136
/// [reportTypes] - List of reportTypes
139-
static void setReportTypes(List<ReportType> reportTypes) async {
140-
final List<String> reportTypesStrings = <String>[];
141-
if (reportTypes != null) {
142-
reportTypes.forEach((e) {
143-
reportTypesStrings.add(e.toString());
144-
});
145-
}
146-
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];
147141
await _channel.invokeMethod<Object>('setReportTypes:', params);
148142
}
149143

150144
/// Sets whether the extended bug report mode should be disabled, enabled with
151145
/// required fields or enabled with optional fields.
152146
/// [extendedBugReportMode] ExtendedBugReportMode enum
153-
static void setExtendedBugReportMode(
147+
static Future<void> setExtendedBugReportMode(
154148
ExtendedBugReportMode extendedBugReportMode) async {
155149
final List<dynamic> params = <dynamic>[extendedBugReportMode.toString()];
156150
await _channel.invokeMethod<Object>('setExtendedBugReportMode:', params);
@@ -159,29 +153,23 @@ class BugReporting {
159153
/// Sets the invocation options.
160154
/// Default is set by `Instabug.startWithToken`.
161155
/// [invocationOptions] List of invocation options
162-
static void setInvocationOptions(
163-
List<InvocationOption> invocationOptions) async {
164-
final List<String> invocationOptionsStrings = <String>[];
165-
if (invocationOptions != null) {
166-
invocationOptions.forEach((e) {
167-
invocationOptionsStrings.add(e.toString());
168-
});
169-
}
170-
final List<dynamic> params = <dynamic>[invocationOptionsStrings];
156+
static Future<void> setInvocationOptions(
157+
List<InvocationOption>? invocationOptions) async {
158+
final invocationOptionsStrings =
159+
invocationOptions?.map((e) => e.toString()).toList(growable: false) ??
160+
[];
161+
final params = <dynamic>[invocationOptionsStrings];
171162
await _channel.invokeMethod<Object>('setInvocationOptions:', params);
172163
}
173164

174165
/// Invoke bug reporting with report type and options.
175166
/// [reportType] type
176167
/// [invocationOptions] List of invocation options
177-
static void show(
178-
ReportType reportType, List<InvocationOption> invocationOptions) async {
179-
final List<String> invocationOptionsStrings = <String>[];
180-
if (invocationOptions != null) {
181-
invocationOptions.forEach((e) {
182-
invocationOptionsStrings.add(e.toString());
183-
});
184-
}
168+
static Future<void> show(
169+
ReportType reportType, List<InvocationOption>? invocationOptions) async {
170+
final invocationOptionsStrings =
171+
invocationOptions?.map((e) => e.toString()).toList(growable: false) ??
172+
[];
185173
final List<dynamic> params = <dynamic>[
186174
reportType.toString(),
187175
invocationOptionsStrings
@@ -193,7 +181,7 @@ class BugReporting {
193181
/// Sets the threshold value of the shake gesture for iPhone/iPod Touch
194182
/// Default for iPhone is 2.5.
195183
/// [iPhoneShakingThreshold] iPhoneShakingThreshold double
196-
static void setShakingThresholdForiPhone(
184+
static Future<void> setShakingThresholdForiPhone(
197185
double iPhoneShakingThreshold) async {
198186
if (Platform.isIOS) {
199187
final List<dynamic> params = <dynamic>[iPhoneShakingThreshold];
@@ -205,7 +193,8 @@ class BugReporting {
205193
/// Sets the threshold value of the shake gesture for iPad
206194
/// Default for iPhone is 0.6.
207195
/// [iPadShakingThreshold] iPhoneShakingThreshold double
208-
static void setShakingThresholdForiPad(double iPadShakingThreshold) async {
196+
static Future<void> setShakingThresholdForiPad(
197+
double iPadShakingThreshold) async {
209198
if (Platform.isIOS) {
210199
final List<dynamic> params = <dynamic>[iPadShakingThreshold];
211200
await _channel.invokeMethod<Object>(
@@ -218,7 +207,8 @@ class BugReporting {
218207
/// you could increase the shaking difficulty level by
219208
/// increasing the `350` value and vice versa
220209
/// [androidThreshold] iPhoneShakingThreshold int
221-
static void setShakingThresholdForAndroid(int androidThreshold) async {
210+
static Future<void> setShakingThresholdForAndroid(
211+
int androidThreshold) async {
222212
if (Platform.isAndroid) {
223213
final List<dynamic> params = <dynamic>[androidThreshold];
224214
await _channel.invokeMethod<Object>(

lib/Chats.dart

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
1+
// ignore_for_file: avoid_classes_with_only_static_members
2+
13
import 'dart:async';
4+
25
import 'package:flutter/services.dart';
36

47
class Chats {
58
static const MethodChannel _channel = MethodChannel('instabug_flutter');
69

7-
static Future<String> get platformVersion async {
8-
final String version = await _channel.invokeMethod('getPlatformVersion');
9-
return version;
10-
}
11-
10+
static Future<String> get platformVersion async =>
11+
(await _channel.invokeMethod<String>('getPlatformVersion'))!;
12+
1213
@deprecated
14+
1315
///Use {@link BugReporting.show} instead.
1416
///Manual invocation for chats view.
15-
static void show() async {
16-
await _channel.invokeMethod<Object>('showChats');
17-
}
17+
static Future<void> show() async =>
18+
await _channel.invokeMethod<Object>('showChats');
1819

1920
@deprecated
21+
2022
///Use {@link BugReporting.setReportTypes} instead.
2123
/// Enables and disables everything related to creating new chats.
2224
/// [boolean] isEnabled
23-
static void setEnabled(bool isEnabled) async {
25+
static Future<void> setEnabled(bool isEnabled) async {
2426
final List<dynamic> params = <dynamic>[isEnabled];
2527
await _channel.invokeMethod<Object>('setChatsEnabled:', params);
2628
}

lib/CrashReporting.dart

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
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;
4-
import 'package:flutter/services.dart';
5+
import 'dart:io' show Platform;
6+
57
import 'package:flutter/foundation.dart';
8+
import 'package:flutter/services.dart';
69
import 'package:instabug_flutter/models/crash_data.dart';
710
import 'package:instabug_flutter/models/exception_data.dart';
811
import 'package:stack_trace/stack_trace.dart';
912

1013
class CrashReporting {
1114
static const MethodChannel _channel = MethodChannel('instabug_flutter');
1215
static bool enabled = true;
13-
static Future<String> get platformVersion async {
14-
final String version = await _channel.invokeMethod('getPlatformVersion');
15-
return version;
16-
}
16+
static Future<String> get platformVersion async =>
17+
(await _channel.invokeMethod<String>('getPlatformVersion'))!;
1718

1819
///Enables and disables Enables and disables automatic crash reporting.
1920
/// [boolean] isEnabled
20-
static void setEnabled(bool isEnabled) async {
21+
static Future<void> setEnabled(bool isEnabled) async {
2122
enabled = isEnabled;
2223
final List<dynamic> params = <dynamic>[isEnabled];
2324
await _channel.invokeMethod<Object>('setCrashReportingEnabled:', params);
2425
}
2526

26-
static void reportCrash(dynamic exception, StackTrace stack) async {
27+
static Future<void> reportCrash(dynamic exception, StackTrace stack) async {
2728
if (kReleaseMode && enabled) {
2829
_reportUnhandledCrash(exception, stack);
2930
} else {
@@ -35,19 +36,21 @@ class CrashReporting {
3536
/// Reports a handled crash to you dashboard
3637
/// [dynamic] exception
3738
/// [StackTrace] stack
38-
static void reportHandledCrash(dynamic exception, [StackTrace stack]) async {
39+
static Future<void> reportHandledCrash(dynamic exception,
40+
[StackTrace? stack]) async {
3941
if (stack != null) {
4042
_sendCrash(exception, stack, true);
4143
} else {
4244
_sendCrash(exception, StackTrace.current, true);
4345
}
4446
}
4547

46-
static void _reportUnhandledCrash(dynamic exception, StackTrace stack) async {
48+
static Future<void> _reportUnhandledCrash(
49+
dynamic exception, StackTrace stack) async {
4750
_sendCrash(exception, stack, false);
4851
}
4952

50-
static void _sendCrash(
53+
static Future<void> _sendCrash(
5154
dynamic exception, StackTrace stack, bool handled) async {
5255
final Trace trace = Trace.from(stack);
5356
final List<ExceptionData> frames = <ExceptionData>[];
@@ -56,7 +59,7 @@ class CrashReporting {
5659
trace.frames[i].uri.toString(),
5760
trace.frames[i].member,
5861
trace.frames[i].line,
59-
trace.frames[i].column == null ? 0 : trace.frames[i].column));
62+
trace.frames[i].column == null ? 0 : trace.frames[i].column!));
6063
}
6164
final CrashData crashData = CrashData(
6265
exception.toString(), Platform.operatingSystem.toString(), frames);

0 commit comments

Comments
 (0)