Skip to content

Commit 3cbcd64

Browse files
committed
Code review comment
1 parent 76af99c commit 3cbcd64

2 files changed

Lines changed: 60 additions & 10 deletions

File tree

lib/features/report_issue/report_issue.dart

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -279,32 +279,51 @@ class _ReportIssueState extends ConsumerState<ReportIssue> {
279279

280280
hideKeyboard();
281281

282+
// Snapshot the validated fields now so later edits (e.g. while the
283+
// confirmation dialog is up or during its dismiss delay) can't change
284+
// what gets sent.
285+
final draft = ref.read(reportIssueDraftProvider);
286+
final issueType = _selectedIssue ?? '';
287+
final email = _emailController.text.trim();
288+
final description = _descriptionController.text.trim();
289+
final attachments = List<ReportIssueAttachment>.of(draft.attachments);
290+
282291
// Without an email we can't reply or follow up, so confirm before sending.
283-
if (_emailController.text.trim().isEmpty) {
292+
if (email.isEmpty) {
284293
AppDialog.show(
285294
context: context,
286295
title: 'send_without_email_title'.i18n,
287296
body: 'send_without_email_body'.i18n,
288297
primaryLabel: 'add_email'.i18n,
289298
secondaryLabel: 'send_without_email'.i18n,
290-
onSecondaryPressed: _performSubmit,
299+
onSecondaryPressed: () => _performSubmit(
300+
email: email,
301+
issueType: issueType,
302+
description: description,
303+
attachments: attachments,
304+
),
291305
);
292306
return;
293307
}
294308

295-
await _performSubmit();
309+
await _performSubmit(
310+
email: email,
311+
issueType: issueType,
312+
description: description,
313+
attachments: attachments,
314+
);
296315
}
297316

298-
Future<void> _performSubmit() async {
317+
Future<void> _performSubmit({
318+
required String email,
319+
required String issueType,
320+
required String description,
321+
required List<ReportIssueAttachment> attachments,
322+
}) async {
299323
if (!mounted) {
300324
return;
301325
}
302326

303-
final draft = ref.read(reportIssueDraftProvider);
304-
final issueType = _selectedIssue ?? '';
305-
final email = _emailController.text.trim();
306-
final description = _descriptionController.text.trim();
307-
308327
context.showLoadingDialog();
309328
appLogger.debug('Submitting issue report: $issueType, $description');
310329

@@ -314,7 +333,7 @@ class _ReportIssueState extends ConsumerState<ReportIssue> {
314333
email: email,
315334
issueType: issueType,
316335
description: description,
317-
attachments: draft.attachments,
336+
attachments: attachments,
318337
);
319338

320339
if (!mounted) {

test/features/report_issue/report_issue_test.dart

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,37 @@ void main() {
300300
expect(submitter.calls, isEmpty);
301301
});
302302

303+
testWidgets('submits the snapshot taken at validation time, not later '
304+
'edits made during the confirmation flow', (tester) async {
305+
await tester.pumpWidget(
306+
buildScreen(screen: const ReportIssue(type: '0')),
307+
);
308+
await tester.pumpAndSettle();
309+
310+
final descriptionField = find.byKey(
311+
const Key('report_issue.description'),
312+
);
313+
await tester.enterText(descriptionField, 'original description');
314+
await tester.pump();
315+
316+
final submitButton = find.byKey(const Key('report_issue.submit_button'));
317+
await tester.ensureVisible(submitButton);
318+
await tester.tap(submitButton);
319+
await tester.pumpAndSettle();
320+
321+
await tester.tap(find.text('send_without_email'));
322+
await tester.pumpAndSettle();
323+
324+
// Edit the form during the dialog's dismiss delay, before the
325+
// confirmed submit fires.
326+
await tester.enterText(descriptionField, 'edited after confirming');
327+
await tester.pump(const Duration(milliseconds: 400));
328+
await tester.pumpAndSettle();
329+
330+
expect(submitter.calls, hasLength(1));
331+
expect(submitter.calls.single.description, 'original description');
332+
});
333+
303334
testWidgets('skips the confirmation dialog when an email is provided', (
304335
tester,
305336
) async {

0 commit comments

Comments
 (0)