Skip to content

Commit e3a75cb

Browse files
fix: bug reporting
1 parent fc8441d commit e3a75cb

File tree

1 file changed

+119
-78
lines changed

1 file changed

+119
-78
lines changed

example/lib/src/screens/bug_reporting.dart

Lines changed: 119 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ class BugReportingPage extends StatefulWidget {
1010
}
1111

1212
class _BugReportingPageState extends State<BugReportingPage> {
13-
List<ReportType> reportTypes = [ReportType.bug,ReportType.feedback,ReportType.question];
13+
List<ReportType> reportTypes = [
14+
ReportType.bug,
15+
ReportType.feedback,
16+
ReportType.question
17+
];
1418
List<InvocationOption> invocationOptions = [];
1519

1620
final disclaimerTextController = TextEditingController();
@@ -19,6 +23,7 @@ class _BugReportingPageState extends State<BugReportingPage> {
1923
bool attachmentsOptionsExtraScreenshot = true;
2024
bool attachmentsOptionsGalleryImage = true;
2125
bool attachmentsOptionsScreenRecording = true;
26+
File? fileAttachment;
2227

2328
void restartInstabug() {
2429
Instabug.setEnabled(false);
@@ -30,13 +35,11 @@ class _BugReportingPageState extends State<BugReportingPage> {
3035
BugReporting.setInvocationEvents([invocationEvent]);
3136
}
3237

33-
void setUserConsent(
34-
String key,
35-
String description,
36-
bool mandatory,
37-
bool checked,
38-
UserConsentActionType? actionType,
39-
) {
38+
void setUserConsent(String key,
39+
String description,
40+
bool mandatory,
41+
bool checked,
42+
UserConsentActionType? actionType,) {
4043
BugReporting.addUserConsents(
4144
key: key,
4245
description: description,
@@ -49,6 +52,21 @@ class _BugReportingPageState extends State<BugReportingPage> {
4952
Instabug.show();
5053
}
5154

55+
Future<void> addFileAttachment() async {
56+
FilePickerResult? result = await FilePicker.platform.pickFiles();
57+
58+
if (result != null) {
59+
fileAttachment = File(result.files.single.path!);
60+
Instabug.addFileAttachmentWithURL(fileAttachment!.path, fileAttachment!.path
61+
.split('/')
62+
.last.substring(0));
63+
}
64+
}
65+
66+
void removeFileAttachment() {
67+
Instabug.clearFileAttachments();
68+
}
69+
5270
void addAttachmentOptions() {
5371
BugReporting.setEnabledAttachmentTypes(
5472
attachmentsOptionsScreenshot,
@@ -84,9 +102,10 @@ class _BugReportingPageState extends State<BugReportingPage> {
84102
if (dismissType == DismissType.submit) {
85103
showDialog(
86104
context: context,
87-
builder: (_) => const AlertDialog(
88-
title: Text('Bug Reporting sent'),
89-
));
105+
builder: (_) =>
106+
const AlertDialog(
107+
title: Text('Bug Reporting sent'),
108+
));
90109
}
91110
});
92111
}
@@ -192,22 +211,24 @@ class _BugReportingPageState extends State<BugReportingPage> {
192211
children: <Widget>[
193212
ElevatedButton(
194213
key: const Key('user_consent_media_manadatory'),
195-
onPressed: () => setUserConsent(
196-
'media_mandatory',
197-
"Mandatory for Media",
198-
true,
199-
true,
200-
UserConsentActionType.dropAutoCapturedMedia),
214+
onPressed: () =>
215+
setUserConsent(
216+
'media_mandatory',
217+
"Mandatory for Media",
218+
true,
219+
true,
220+
UserConsentActionType.dropAutoCapturedMedia),
201221
child: const Text('Drop Media Mandatory'),
202222
),
203223
ElevatedButton(
204224
key: const Key('user_consent_no_chat_manadatory'),
205-
onPressed: () => setUserConsent(
206-
'noChat_mandatory',
207-
"Mandatory for No Chat",
208-
true,
209-
true,
210-
UserConsentActionType.noChat),
225+
onPressed: () =>
226+
setUserConsent(
227+
'noChat_mandatory',
228+
"Mandatory for No Chat",
229+
true,
230+
true,
231+
UserConsentActionType.noChat),
211232
child: const Text('No Chat Mandatory'),
212233
),
213234
],
@@ -219,22 +240,24 @@ class _BugReportingPageState extends State<BugReportingPage> {
219240
children: <Widget>[
220241
ElevatedButton(
221242
key: const Key('user_consent_drop_logs_manadatory'),
222-
onPressed: () => setUserConsent(
223-
'dropLogs_mandatory',
224-
"Mandatory for Drop logs",
225-
true,
226-
true,
227-
UserConsentActionType.dropLogs),
243+
onPressed: () =>
244+
setUserConsent(
245+
'dropLogs_mandatory',
246+
"Mandatory for Drop logs",
247+
true,
248+
true,
249+
UserConsentActionType.dropLogs),
228250
child: const Text('Drop logs Mandatory'),
229251
),
230252
ElevatedButton(
231253
key: const Key('user_consent_no_chat_optional'),
232-
onPressed: () => setUserConsent(
233-
'noChat_mandatory',
234-
"Optional for No Chat",
235-
false,
236-
true,
237-
UserConsentActionType.noChat),
254+
onPressed: () =>
255+
setUserConsent(
256+
'noChat_mandatory',
257+
"Optional for No Chat",
258+
false,
259+
true,
260+
UserConsentActionType.noChat),
238261
child: const Text('No Chat optional'),
239262
),
240263
],
@@ -246,8 +269,9 @@ class _BugReportingPageState extends State<BugReportingPage> {
246269
children: <Widget>[
247270
ElevatedButton(
248271
key: const Key('invocation_option_disable_post_sending_dialog'),
249-
onPressed: () => addInvocationOption(
250-
InvocationOption.disablePostSendingDialog),
272+
onPressed: () =>
273+
addInvocationOption(
274+
InvocationOption.disablePostSendingDialog),
251275
child: const Text('disablePostSendingDialog'),
252276
),
253277
ElevatedButton(
@@ -305,7 +329,6 @@ class _BugReportingPageState extends State<BugReportingPage> {
305329
attachmentsOptionsExtraScreenshot = value ?? false;
306330
});
307331
addAttachmentOptions();
308-
309332
},
310333
title: const Text("Extra Screenshot"),
311334
subtitle: const Text('Enable attachment for extra screenShot'),
@@ -319,7 +342,6 @@ class _BugReportingPageState extends State<BugReportingPage> {
319342
attachmentsOptionsGalleryImage = value ?? false;
320343
});
321344
addAttachmentOptions();
322-
323345
},
324346
title: const Text("Gallery"),
325347
subtitle: const Text('Enable attachment for gallery'),
@@ -333,7 +355,6 @@ class _BugReportingPageState extends State<BugReportingPage> {
333355
attachmentsOptionsScreenRecording = value ?? false;
334356
});
335357
addAttachmentOptions();
336-
337358
},
338359
title: const Text("Screen Recording"),
339360
subtitle: const Text('Enable attachment for screen Recording'),
@@ -344,38 +365,46 @@ class _BugReportingPageState extends State<BugReportingPage> {
344365
),
345366
const SectionTitle('Bug reporting type'),
346367

347-
ButtonBar(
348-
mainAxisSize: MainAxisSize.min,
349-
alignment: MainAxisAlignment.start,
350-
children: <Widget>[
351-
ElevatedButton(
352-
key: const Key('bug_report_type_bug'),
353-
style: ElevatedButton.styleFrom(
354-
backgroundColor: reportTypes.contains(ReportType.bug)?Colors.grey.shade400:null
355-
),
356-
onPressed: () => toggleReportType(ReportType.bug),
357-
child: const Text('Bug'),
358-
),
359-
ElevatedButton(
360-
key: const Key('bug_report_type_feedback'),
361-
onPressed: () => toggleReportType(ReportType.feedback),
362-
style: ElevatedButton.styleFrom(
363-
backgroundColor: reportTypes.contains(ReportType.feedback)?Colors.grey.shade400:null
364-
),
365-
child: const Text('Feedback'),
366-
),
367-
ElevatedButton(
368-
key: const Key('bug_report_type_question'),
369-
onPressed: () => toggleReportType(ReportType.question),
370-
style: ElevatedButton.styleFrom(
371-
backgroundColor: reportTypes.contains(ReportType.question)?Colors.grey.shade400:null
372-
),
373-
child: const Text('Question'),
374-
),
375-
],
368+
CheckboxListTile(
369+
value: reportTypes.contains(ReportType.bug),
370+
onChanged: (value) {
371+
toggleReportType(ReportType.bug);
372+
setState(() {
373+
});
374+
},
375+
title: const Text("Bug"),
376+
subtitle: const Text('Enable Bug reporting type'),
377+
key: const Key('bug_report_type_bug'),
378+
379+
),
380+
CheckboxListTile(
381+
value: reportTypes.contains(ReportType.feedback),
382+
onChanged: (value) {
383+
toggleReportType(ReportType.feedback);
384+
setState(() {
385+
});
386+
},
387+
title: const Text("Feedback"),
388+
subtitle: const Text('Enable Feedback reporting type'),
389+
key: const Key('bug_report_type_feedback'),
390+
391+
),
392+
393+
CheckboxListTile(
394+
value: reportTypes.contains(ReportType.question),
395+
onChanged: (value) {
396+
toggleReportType(ReportType.question);
397+
setState(() {
398+
});
399+
},
400+
title: const Text("Question"),
401+
subtitle: const Text('Enable Question reporting type'),
402+
key: const Key('bug_report_type_question'),
403+
376404
),
377405
InstabugButton(
378-
onPressed: () => {
406+
onPressed: () =>
407+
{
379408
BugReporting.show(
380409
ReportType.bug, [InvocationOption.emailFieldOptional])
381410
},
@@ -400,15 +429,17 @@ class _BugReportingPageState extends State<BugReportingPage> {
400429
children: <Widget>[
401430
ElevatedButton(
402431
key: const Key('extended_bug_report_mode_disabled'),
403-
onPressed: () => BugReporting.setExtendedBugReportMode(
404-
ExtendedBugReportMode.disabled),
432+
onPressed: () =>
433+
BugReporting.setExtendedBugReportMode(
434+
ExtendedBugReportMode.disabled),
405435
child: const Text('disabled'),
406436
),
407437
ElevatedButton(
408438
key:
409-
const Key('extended_bug_report_mode_required_fields_enabled'),
410-
onPressed: () => BugReporting.setExtendedBugReportMode(
411-
ExtendedBugReportMode.enabledWithRequiredFields),
439+
const Key('extended_bug_report_mode_required_fields_enabled'),
440+
onPressed: () =>
441+
BugReporting.setExtendedBugReportMode(
442+
ExtendedBugReportMode.enabledWithRequiredFields),
412443
child: const Text('enabledWithRequiredFields'),
413444
),
414445
],
@@ -419,9 +450,10 @@ class _BugReportingPageState extends State<BugReportingPage> {
419450
children: <Widget>[
420451
ElevatedButton(
421452
key:
422-
const Key('extended_bug_report_mode_optional_fields_enabled'),
423-
onPressed: () => BugReporting.setExtendedBugReportMode(
424-
ExtendedBugReportMode.enabledWithOptionalFields),
453+
const Key('extended_bug_report_mode_optional_fields_enabled'),
454+
onPressed: () =>
455+
BugReporting.setExtendedBugReportMode(
456+
ExtendedBugReportMode.enabledWithOptionalFields),
425457
child: const Text('enabledWithOptionalFields'),
426458
),
427459
],
@@ -431,6 +463,15 @@ class _BugReportingPageState extends State<BugReportingPage> {
431463
onPressed: setOnDismissCallback,
432464
text: 'Set On Dismiss Callback',
433465
),
466+
const SectionTitle('Attachments'),
467+
InstabugButton(
468+
onPressed: addFileAttachment,
469+
text: 'Add file attachment',
470+
),
471+
InstabugButton(
472+
onPressed: removeFileAttachment,
473+
text: 'Clear All attachment',
474+
),
434475
], // This trailing comma makes auto-formatting nicer for build methods.
435476
);
436477
}

0 commit comments

Comments
 (0)