Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion feedback/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class _MyAppState extends State<MyApp> {
// If custom feedback is not enabled, supply null and the default text
// feedback form will be used.
feedbackBuilder: _useCustomFeedback
? (context, onSubmit, scrollController) => CustomFeedbackForm(
? (context, onSubmit, scrollController, showLoading) =>
CustomFeedbackForm(
onSubmit: onSubmit,
scrollController: scrollController,
)
Expand Down
3 changes: 3 additions & 0 deletions feedback/lib/src/better_feedback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ typedef OnSubmit = Future<void> Function(
Map<String, dynamic>? extras,
});

typedef ShowLoading = bool;

/// A function that returns a Widget that prompts the user for feedback and
/// calls [OnSubmit] when the user wants to submit their feedback.
///
Expand All @@ -31,6 +33,7 @@ typedef FeedbackBuilder = Widget Function(
BuildContext,
OnSubmit,
ScrollController?,
ShowLoading,
);

/// A drag handle to be placed at the top of a draggable feedback sheet.
Expand Down
7 changes: 7 additions & 0 deletions feedback/lib/src/feedback_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ class FeedbackBottomSheet extends StatelessWidget {
required this.feedbackBuilder,
required this.onSubmit,
required this.sheetProgress,
required this.showLoading,
});

final FeedbackBuilder feedbackBuilder;
final OnSubmit onSubmit;
final ValueNotifier<double> sheetProgress;
final bool showLoading;

@override
Widget build(BuildContext context) {
Expand All @@ -26,6 +28,7 @@ class FeedbackBottomSheet extends StatelessWidget {
feedbackBuilder: feedbackBuilder,
onSubmit: onSubmit,
sheetProgress: sheetProgress,
showLoading: showLoading,
),
);
}
Expand All @@ -45,6 +48,7 @@ class FeedbackBottomSheet extends StatelessWidget {
context,
onSubmit,
null,
showLoading,
),
);
},
Expand All @@ -60,11 +64,13 @@ class _DraggableFeedbackSheet extends StatefulWidget {
required this.feedbackBuilder,
required this.onSubmit,
required this.sheetProgress,
required this.showLoading,
});

final FeedbackBuilder feedbackBuilder;
final OnSubmit onSubmit;
final ValueNotifier<double> sheetProgress;
final bool showLoading;

@override
State<_DraggableFeedbackSheet> createState() =>
Expand Down Expand Up @@ -138,6 +144,7 @@ class _DraggableFeedbackSheetState extends State<_DraggableFeedbackSheet> {
context,
widget.onSubmit,
scrollController,
widget.showLoading,
),
);
},
Expand Down
33 changes: 22 additions & 11 deletions feedback/lib/src/feedback_builder/string_feedback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ Widget simpleFeedbackBuilder(
BuildContext context,
OnSubmit onSubmit,
ScrollController? scrollController,
bool showLoading,
) =>
StringFeedback(onSubmit: onSubmit, scrollController: scrollController);
StringFeedback(
onSubmit: onSubmit,
scrollController: scrollController,
showLoading: showLoading,
);

/// A form that prompts the user for feedback with a single text field.
/// This is the default feedback widget used by [BetterFeedback].
Expand All @@ -20,11 +25,15 @@ class StringFeedback extends StatefulWidget {
super.key,
required this.onSubmit,
required this.scrollController,
required this.showLoading,
});

/// Should be called when the user taps the submit button.
final OnSubmit onSubmit;

/// show CircularProgressIndicator when Submiting
final bool showLoading;

/// A scroll controller that expands the sheet when it's attached to a
/// scrollable widget and that widget is scrolled.
///
Expand Down Expand Up @@ -88,16 +97,18 @@ class _StringFeedbackState extends State<StringFeedback> {
],
),
),
TextButton(
key: const Key('submit_feedback_button'),
child: Text(
FeedbackLocalizations.of(context).submitButtonText,
style: TextStyle(
color: FeedbackTheme.of(context).activeFeedbackModeColor,
),
),
onPressed: () => widget.onSubmit(controller.text),
),
widget.showLoading
? CircularProgressIndicator()
: TextButton(
key: const Key('submit_feedback_button'),
child: Text(
FeedbackLocalizations.of(context).submitButtonText,
style: TextStyle(
color: FeedbackTheme.of(context).activeFeedbackModeColor,
),
),
onPressed: () => widget.onSubmit(controller.text),
),
const SizedBox(height: 8),
],
);
Expand Down
8 changes: 8 additions & 0 deletions feedback/lib/src/feedback_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class FeedbackWidgetState extends State<FeedbackWidget>
with SingleTickerProviderStateMixin {
// Padding to put around the interactive screenshot preview.
final double padding = 8;
bool showLoading = false;

// We use a ValueNotifier instead of just a double and `SetState` because
// rebuilding the feedback sheet mid-drag cancels the drag.
Expand Down Expand Up @@ -263,10 +264,14 @@ class FeedbackWidgetState extends State<FeedbackWidget>
child: FeedbackBottomSheet(
key: const Key('feedback_bottom_sheet'),
feedbackBuilder: widget.feedbackBuilder,
showLoading: showLoading,
onSubmit: (
String feedback, {
Map<String, dynamic>? extras,
}) async {
setState(() {
showLoading = true;
});
await _sendFeedback(
context,
BetterFeedback.of(context).onFeedback!,
Expand All @@ -275,6 +280,9 @@ class FeedbackWidgetState extends State<FeedbackWidget>
widget.pixelRatio,
extras: extras,
);
setState(() {
showLoading = false;
});
painterController.clear();
},
sheetProgress: sheetProgress,
Expand Down
2 changes: 1 addition & 1 deletion feedback/test/feedback_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ void main() {
submittedFeedback = feedback;
},
),
feedbackBuilder: (context, onSubmit, controller) {
feedbackBuilder: (context, onSubmit, controller, showLoading) {
return SingleChildScrollView(
controller: controller,
child: TextButton(
Expand Down