1
+ // ignore_for_file: avoid_classes_with_only_static_members
2
+
1
3
import 'dart:async' ;
2
4
import 'dart:io' show Platform;
5
+
3
6
import 'package:flutter/services.dart' ;
4
7
import 'package:instabug_flutter/Instabug.dart' ;
5
8
@@ -21,24 +24,22 @@ enum ExtendedBugReportMode {
21
24
}
22
25
23
26
class BugReporting {
24
- static Function _onInvokeCallback;
25
- static Function _onDismissCallback;
27
+ static Function ? _onInvokeCallback;
28
+ static Function ? _onDismissCallback;
26
29
static const MethodChannel _channel = MethodChannel ('instabug_flutter' );
27
30
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' ))! ;
32
33
33
34
static Future <dynamic > _handleMethod (MethodCall call) async {
34
35
switch (call.method) {
35
36
case 'onInvokeCallback' :
36
- _onInvokeCallback ();
37
+ _onInvokeCallback? . call ();
37
38
return ;
38
39
case 'onDismissCallback' :
39
40
final Map <dynamic , dynamic > map = call.arguments;
40
- DismissType dismissType;
41
- ReportType reportType;
41
+ DismissType ? dismissType;
42
+ ReportType ? reportType;
42
43
final String dismissTypeString = map['dismissType' ].toUpperCase ();
43
44
switch (dismissTypeString) {
44
45
case 'CANCEL' :
@@ -64,17 +65,17 @@ class BugReporting {
64
65
break ;
65
66
}
66
67
try {
67
- _onDismissCallback (dismissType, reportType);
68
+ _onDismissCallback? . call (dismissType, reportType);
68
69
} catch (exception) {
69
- _onDismissCallback ();
70
+ _onDismissCallback? . call ();
70
71
}
71
72
return ;
72
73
}
73
74
}
74
75
75
76
///Enables and disables manual invocation and prompt options for bug and feedback.
76
77
/// [boolean] isEnabled
77
- static void setEnabled (bool isEnabled) async {
78
+ static Future < void > setEnabled (bool isEnabled) async {
78
79
final List <dynamic > params = < dynamic > [isEnabled];
79
80
await _channel.invokeMethod <Object >('setBugReportingEnabled:' , params);
80
81
}
@@ -83,7 +84,7 @@ class BugReporting {
83
84
/// This block is executed on the UI thread. Could be used for performing any
84
85
/// UI changes before the SDK's UI is shown.
85
86
/// [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 {
87
88
_channel.setMethodCallHandler (_handleMethod);
88
89
_onInvokeCallback = function;
89
90
await _channel.invokeMethod <Object >('setOnInvokeCallback' );
@@ -93,7 +94,7 @@ class BugReporting {
93
94
/// This block is executed on the UI thread. Could be used for performing any
94
95
/// UI changes before the SDK's UI is shown.
95
96
/// [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 {
97
98
_channel.setMethodCallHandler (_handleMethod);
98
99
_onDismissCallback = function;
99
100
await _channel.invokeMethod <Object >('setOnDismissCallback' );
@@ -102,15 +103,12 @@ class BugReporting {
102
103
/// Sets the events that invoke the feedback form.
103
104
/// Default is set by `Instabug.startWithToken` .
104
105
/// [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];
114
112
await _channel.invokeMethod <Object >('setInvocationEvents:' , params);
115
113
}
116
114
@@ -121,8 +119,8 @@ class BugReporting {
121
119
/// attachments. In iOS 10+,NSPhotoLibraryUsageDescription should be set in
122
120
/// info.plist to enable gallery image attachments.
123
121
/// [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 {
126
124
final List <dynamic > params = < dynamic > [
127
125
screenshot,
128
126
extraScreenshot,
@@ -136,21 +134,17 @@ class BugReporting {
136
134
137
135
///Sets what type of reports, bug or feedback, should be invoked.
138
136
/// [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];
147
141
await _channel.invokeMethod <Object >('setReportTypes:' , params);
148
142
}
149
143
150
144
/// Sets whether the extended bug report mode should be disabled, enabled with
151
145
/// required fields or enabled with optional fields.
152
146
/// [extendedBugReportMode] ExtendedBugReportMode enum
153
- static void setExtendedBugReportMode (
147
+ static Future < void > setExtendedBugReportMode (
154
148
ExtendedBugReportMode extendedBugReportMode) async {
155
149
final List <dynamic > params = < dynamic > [extendedBugReportMode.toString ()];
156
150
await _channel.invokeMethod <Object >('setExtendedBugReportMode:' , params);
@@ -159,29 +153,23 @@ class BugReporting {
159
153
/// Sets the invocation options.
160
154
/// Default is set by `Instabug.startWithToken` .
161
155
/// [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];
171
162
await _channel.invokeMethod <Object >('setInvocationOptions:' , params);
172
163
}
173
164
174
165
/// Invoke bug reporting with report type and options.
175
166
/// [reportType] type
176
167
/// [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
+ [];
185
173
final List <dynamic > params = < dynamic > [
186
174
reportType.toString (),
187
175
invocationOptionsStrings
@@ -193,7 +181,7 @@ class BugReporting {
193
181
/// Sets the threshold value of the shake gesture for iPhone/iPod Touch
194
182
/// Default for iPhone is 2.5.
195
183
/// [iPhoneShakingThreshold] iPhoneShakingThreshold double
196
- static void setShakingThresholdForiPhone (
184
+ static Future < void > setShakingThresholdForiPhone (
197
185
double iPhoneShakingThreshold) async {
198
186
if (Platform .isIOS) {
199
187
final List <dynamic > params = < dynamic > [iPhoneShakingThreshold];
@@ -205,7 +193,8 @@ class BugReporting {
205
193
/// Sets the threshold value of the shake gesture for iPad
206
194
/// Default for iPhone is 0.6.
207
195
/// [iPadShakingThreshold] iPhoneShakingThreshold double
208
- static void setShakingThresholdForiPad (double iPadShakingThreshold) async {
196
+ static Future <void > setShakingThresholdForiPad (
197
+ double iPadShakingThreshold) async {
209
198
if (Platform .isIOS) {
210
199
final List <dynamic > params = < dynamic > [iPadShakingThreshold];
211
200
await _channel.invokeMethod <Object >(
@@ -218,7 +207,8 @@ class BugReporting {
218
207
/// you could increase the shaking difficulty level by
219
208
/// increasing the `350` value and vice versa
220
209
/// [androidThreshold] iPhoneShakingThreshold int
221
- static void setShakingThresholdForAndroid (int androidThreshold) async {
210
+ static Future <void > setShakingThresholdForAndroid (
211
+ int androidThreshold) async {
222
212
if (Platform .isAndroid) {
223
213
final List <dynamic > params = < dynamic > [androidThreshold];
224
214
await _channel.invokeMethod <Object >(
0 commit comments