Skip to content

Commit 8c8e541

Browse files
denrasebuenaflor
andauthored
SentryFeedbackWidget Improvements (#2964)
* Read default values from options * Add screenshot from camera roll * Implmenet „Take Screenshot“ functionality * move things around * only read from feedback options * remove unused import * revert sentry widget changes * make final instead of late final * removeredundant comments * implement @ueman feedback * ui customization, logo, tests * update and fix tests * set screenshot, fix button shape * cleanup, changelog * revert * cleanup * move key to button * move key to button * replace spacing with sizedbox * fix logo * update cl * Remove iamge picking for now * remove generated files when running example * fix comment * remove feature from cl * remove addScreenshotButtonLabel * remove unneccessary call, which is also not available on lower sdk versions * update cl * Fix spelling error * Save and restore form data when taking a screenshot * fix cl * Capture replay when feedback widget is opened * Add integration name when feedback options are accessed * implement mock stub * update changelog * flush replay on manual feedback * format * add comment * introduce internal typecheckhint * format * format --------- Co-authored-by: Giancarlo Buenaflor <giancarlo_buenaflor@yahoo.com> Co-authored-by: Giancarlo Buenaflor <giancarlobuenaflor97@gmail.com>
1 parent 47f7146 commit 8c8e541

15 files changed

+1263
-176
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
- Add os and device attributes to Flutter logs ([#2978](https://github.com/getsentry/sentry-dart/pull/2978))
88
- String templating for structured logs ([#3002](https://github.com/getsentry/sentry-dart/pull/3002))
99
- Add user attributes to Dart/Flutter logs ([#3014](https://github.com/getsentry/sentry-dart/pull/3002))
10+
- SentryFeedbackWidget Improvements ([#2964](https://github.com/getsentry/sentry-dart/pull/2964))
11+
- Capture a device screenshot for feedback
12+
- Customize tests and required fields
13+
- Customization moved from the `SentryFeedbackWidget` constructor to `SentryFlutterOptions`:
14+
```dart
15+
options.feedback.showBranding = false;
16+
```
1017

1118
### Fixes
1219

@@ -59,6 +66,7 @@ void initState() {
5966
```
6067
- Add `message` parameter to `captureException()` ([#2882](https://github.com/getsentry/sentry-dart/pull/2882))
6168
- Add module in SentryStackFrame ([#2931](https://github.com/getsentry/sentry-dart/pull/2931))
69+
- Set `SentryOptions.includeModuleInStackTrace = true` to enable this. This may change grouping of exceptions.
6270
- Set `SentryOptions.includeModuleInStackTrace = true` to enable this. This may change grouping of exceptions.
6371

6472
### Dependencies

dart/lib/src/sentry_attachment/sentry_attachment.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,12 @@ class SentryAttachment {
8989
);
9090

9191
SentryAttachment.fromScreenshotData(Uint8List bytes)
92-
: this.fromUint8List(bytes, 'screenshot.png',
93-
contentType: 'image/png',
94-
attachmentType: SentryAttachment.typeAttachmentDefault);
92+
: this.fromUint8List(
93+
bytes,
94+
'screenshot.png',
95+
contentType: 'image/png',
96+
attachmentType: SentryAttachment.typeAttachmentDefault,
97+
);
9598

9699
SentryAttachment.fromViewHierarchy(SentryViewHierarchy sentryViewHierarchy)
97100
: this.fromLoader(

dart/lib/src/type_check_hint.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:meta/meta.dart';
12
import 'http_client/failed_request_client.dart';
23

34
/// Constants used for Type Check hints.
@@ -19,4 +20,7 @@ class TypeCheckHint {
1920

2021
/// Used to indicate that the SDK added a synthetic current stack trace.
2122
static const currentStackTrace = 'currentStackTrace';
23+
24+
@internal
25+
static const isWidgetFeedback = 'isWidgetFeedback';
2226
}

flutter/example/lib/main.dart

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -513,16 +513,10 @@ class MainScaffold extends StatelessWidget {
513513
TooltipButton(
514514
onPressed: () async {
515515
final id = await Sentry.captureMessage('UserFeedback');
516-
final screenshot = await SentryFlutter.captureScreenshot();
517-
518516
if (!context.mounted) return;
519-
Navigator.push(
517+
SentryFeedbackWidget.show(
520518
context,
521-
MaterialPageRoute(
522-
builder: (context) => SentryFeedbackWidget(
523-
associatedEventId: id, screenshot: screenshot),
524-
fullscreenDialog: true,
525-
),
519+
associatedEventId: id,
526520
);
527521
},
528522
text:

flutter/lib/src/event_processor/replay_event_processor.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@ class ReplayEventProcessor implements EventProcessor {
1212

1313
@override
1414
Future<SentryEvent?> apply(SentryEvent event, Hint hint) async {
15-
final hasException = event.eventId != SentryId.empty() &&
15+
final isErrorEvent = event.eventId != SentryId.empty() &&
1616
event.exceptions?.isNotEmpty == true;
17-
final isFeedback =
17+
18+
final isFeedbackEvent =
1819
event.eventId != SentryId.empty() && event.type == 'feedback';
19-
final shouldCaptureReplay = hasException || isFeedback;
20+
final isWidgetFeedbackEvent =
21+
// ignore: invalid_use_of_internal_member
22+
hint.get(TypeCheckHint.isWidgetFeedback) == true;
23+
24+
final shouldCaptureReplay =
25+
isErrorEvent || (isFeedbackEvent && !isWidgetFeedbackEvent);
2026

2127
if (shouldCaptureReplay) {
2228
final isCrash =
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
class SentryFeedbackOptions {
2+
// Form Configuration
3+
4+
/// The title of the feedback form.
5+
var title = 'Report a Bug';
6+
7+
/// Requires the name field on the feedback form to be filled in.
8+
var isNameRequired = false;
9+
10+
/// Displays the name field on the feedback form. Ignored if `isNameRequired` is `true`.
11+
var showName = true;
12+
13+
/// Requires the email field on the feedback form to be filled in.
14+
var isEmailRequired = false;
15+
16+
/// Displays the email field on the feedback form. Ignored if `isEmailRequired` is `true`.
17+
var showEmail = true;
18+
19+
/// Sets the `email` and `name` fields to the corresponding Sentry SDK user fields that were called with `SentrySDK.setUser`.
20+
var useSentryUser = true;
21+
22+
/// Displays the Sentry logo inside the form
23+
var showBranding = true;
24+
25+
/// Displays the capture screenshot button on the feedback form
26+
var showCaptureScreenshot = true;
27+
28+
// Form Labels Configuration
29+
30+
/// The title of the feedback form.
31+
String formTitle = 'Report a Bug';
32+
33+
/// The label of the feedback description input field.
34+
String messageLabel = 'Description';
35+
36+
/// The placeholder in the feedback description input field.
37+
String messagePlaceholder = 'What\'s the bug? What did you expect?';
38+
39+
/// The text to attach to the title label for a required field.
40+
String isRequiredLabel = ' (Required)';
41+
42+
/// The message displayed after a successful feedback submission.
43+
String successMessageText = 'Thank you for your report!';
44+
45+
/// The label next to the name input field.
46+
String nameLabel = 'Name';
47+
48+
/// The placeholder in the name input field.
49+
String namePlaceholder = 'Your Name';
50+
51+
/// The label next to the email input field.
52+
String emailLabel = 'Email';
53+
54+
/// The placeholder in the email input field.
55+
String emailPlaceholder = 'your.email@example.org';
56+
57+
/// The label of the submit button.
58+
String submitButtonLabel = 'Send Bug Report';
59+
60+
/// The label of the cancel button.
61+
String cancelButtonLabel = 'Cancel';
62+
63+
/// The label of the validation error message.
64+
String validationErrorLabel = 'Can\'t be empty';
65+
66+
/// The label of the capture screenshot button.
67+
String captureScreenshotButtonLabel = 'Capture a screenshot';
68+
69+
/// The label of the remove screenshot button.
70+
String removeScreenshotButtonLabel = 'Remove screenshot';
71+
72+
/// The label of the take screenshot button shown outside of the feedback widget.
73+
String takeScreenshotButtonLabel = 'Take Screenshot';
74+
}

0 commit comments

Comments
 (0)