11import 'dart:async' ;
2+ import 'package:flutter/foundation.dart' ;
23import 'package:flutter/services.dart' ;
34import 'package:instabug_flutter/Instabug.dart' ;
45
@@ -9,13 +10,71 @@ enum InvocationOption {
910 EMAIL_FIELD_OPTIONAL
1011}
1112
13+ enum DismissType {
14+ CANCEL ,
15+ SUBMIT ,
16+ ADD_ATTACHMENT
17+ }
18+
19+ enum ReportType {
20+ BUG ,
21+ FEEDBACK ,
22+ OTHER
23+ }
24+
1225class BugReporting {
26+
27+ static Function onInvokeCallback;
28+ static Function onDismissCallback;
1329 static const MethodChannel _channel = MethodChannel ('instabug_flutter' );
1430
1531 static Future <String > get platformVersion async {
1632 final String version = await _channel.invokeMethod ('getPlatformVersion' );
1733 return version;
1834 }
35+
36+ static Future <dynamic > _handleMethod (MethodCall call) async {
37+ switch (call.method) {
38+ case 'onInvokeCallback' :
39+ onInvokeCallback ();
40+ return ;
41+ case 'onDismissCallback' :
42+ Map <dynamic , dynamic > map = call.arguments;
43+ DismissType dismissType;
44+ ReportType reportType;
45+ final String dismissTypeString = map['dismissType' ].toUpperCase ();
46+ switch (dismissTypeString) {
47+ case 'CANCEL' :
48+ dismissType = DismissType .CANCEL ;
49+ break ;
50+ case 'SUBMIT' :
51+ dismissType = DismissType .SUBMIT ;
52+ break ;
53+ case 'ADD_ATTACHMENT' :
54+ dismissType = DismissType .ADD_ATTACHMENT ;
55+ break ;
56+ }
57+ final String reportTypeString = map['reportType' ].toUpperCase ();
58+ switch (reportTypeString) {
59+ case 'BUG' :
60+ reportType = ReportType .BUG ;
61+ break ;
62+ case 'FEEDBACK' :
63+ reportType = ReportType .FEEDBACK ;
64+ break ;
65+ case 'OTHER' :
66+ reportType = ReportType .OTHER ;
67+ break ;
68+ }
69+ try {
70+ onDismissCallback (dismissType,reportType);
71+ }
72+ catch (exception) {
73+ onDismissCallback ();
74+ }
75+ return ;
76+ }
77+ }
1978 /// invoke sdk manually with desire invocation mode
2079 /// [invocationMode] the invocation mode
2180 /// [invocationOptions] the array of invocation options
@@ -29,4 +88,31 @@ class BugReporting {
2988 final List <dynamic > params = < dynamic > [invocationMode.toString (), invocationOptionsStrings];
3089 await _channel.invokeMethod <Object >('invokeWithMode:options:' ,params);
3190 }
32- }
91+
92+ ///Enables and disables manual invocation and prompt options for bug and feedback.
93+ /// [boolean] isEnabled
94+ static void setEnabled (bool isEnabled) async {
95+ final List <dynamic > params = < dynamic > [isEnabled];
96+ await _channel.invokeMethod <Object >('setBugReportingEnabled:' , params);
97+ }
98+
99+ /// Sets a block of code to be executed just before the SDK's UI is presented.
100+ /// This block is executed on the UI thread. Could be used for performing any
101+ /// UI changes before the SDK's UI is shown.
102+ /// [function] A callback that gets executed before invoking the SDK
103+ static void setOnInvokeCallback (Function function) async {
104+ _channel.setMethodCallHandler (_handleMethod);
105+ onInvokeCallback = function;
106+ await _channel.invokeMethod <Object >('setOnInvokeCallback' );
107+ }
108+
109+ /// Sets a block of code to be executed just before the SDK's UI is presented.
110+ /// This block is executed on the UI thread. Could be used for performing any
111+ /// UI changes before the SDK's UI is shown.
112+ /// [function] A callback that gets executed before invoking the SDK
113+ static void setOnDismissCallback (Function function) async {
114+ _channel.setMethodCallHandler (_handleMethod);
115+ onDismissCallback = function;
116+ await _channel.invokeMethod <Object >('setOnDismissCallback' );
117+ }
118+ }
0 commit comments