-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Expand file tree
/
Copy pathfeedback.dart
More file actions
91 lines (79 loc) · 2.62 KB
/
feedback.dart
File metadata and controls
91 lines (79 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2025 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:jaspr/dom.dart';
import 'package:jaspr/jaspr.dart';
import '../../../analytics/analytics.dart';
import '../button.dart';
/// Provides the user options to provide feedback on the specified page.
@client
final class FeedbackComponent extends StatefulComponent {
const FeedbackComponent({required this.issueUrl});
final String issueUrl;
@override
State<FeedbackComponent> createState() => _FeedbackComponentState();
}
final class _FeedbackComponentState extends State<FeedbackComponent> {
_FeedbackState feedback = _FeedbackState.none;
void _provideFeedback({required bool helpful}) {
if (!kIsWeb) return;
setState(
() => feedback = helpful
? _FeedbackState.helpful
: _FeedbackState.unhelpful,
);
analytics.sendFeedback(helpful);
}
@override
Component build(BuildContext context) {
return div(id: 'page-feedback', [
div(classes: 'feedback', [
div([.text(feedback.introduction)]),
...switch (feedback) {
_FeedbackState.none => [
div(classes: 'feedback-buttons', [
Button(
icon: 'thumb_up',
title: 'Yes, this page was helpful.',
onClick: () => _provideFeedback(helpful: true),
),
Button(
icon: 'thumb_down',
title: 'No, this page was not helpful or had an issue',
onClick: () => _provideFeedback(helpful: false),
),
]),
],
_FeedbackState.helpful => [
Button(
content: 'Provide details',
icon: 'feedback',
title: 'Provide detailed feedback.',
href: component.issueUrl,
attributes: const {'target': '_blank', 'rel': 'noopener'},
),
],
_FeedbackState.unhelpful => [
Button(
content: 'Provide details',
icon: 'bug_report',
title: 'Provide feedback or report an issue.',
href: component.issueUrl,
attributes: const {'target': '_blank', 'rel': 'noopener'},
),
],
},
]),
]);
}
}
enum _FeedbackState {
none('Was this page\'s content helpful?'),
helpful('Thank you for your feedback!'),
unhelpful(
'Thank you for your feedback! '
'Please let us know what we can do to improve.',
);
const _FeedbackState(this.introduction);
final String introduction;
}