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
4 changes: 3 additions & 1 deletion lib/widgets/dialog.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import '../generated/l10n/zulip_localizations.dart';
Comment on lines +4 to 6

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
import 'package:flutter/services.dart';
import '../generated/l10n/zulip_localizations.dart';
import 'package:flutter/services.dart';
import '../generated/l10n/zulip_localizations.dart';

import '../model/settings.dart';
Expand Down Expand Up @@ -146,7 +147,7 @@ class DialogStatus<T> {
}

/// Displays an [AlertDialog] with a dismiss button
/// and optional "Learn more" button.
/// and optional "Learn more" button, and gives haptic feedback.
///
/// The [DialogStatus.result] field of the return value can be used
/// for waiting for the dialog to be closed.
Expand All @@ -165,6 +166,7 @@ DialogStatus<void> showErrorDialog({
String? message,
Uri? learnMoreButtonUrl,
}) {
HapticFeedback.errorNotification();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's mention this new behavior in the dartdoc of showErrorDialog.

final zulipLocalizations = ZulipLocalizations.of(context);
final future = showDialog<void>(
context: context,
Expand Down
23 changes: 23 additions & 0 deletions test/widgets/dialog_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:checks/checks.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_checks/flutter_checks.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:url_launcher/url_launcher.dart';
Expand Down Expand Up @@ -38,6 +39,28 @@ void main() {
checkErrorDialog(tester, expectedTitle: title, expectedMessage: message);
}, variant: const TargetPlatformVariant({TargetPlatform.android, TargetPlatform.iOS}));

testWidgets('triggers error haptic feedback', (tester) async {
await prepare(tester);

final calls = <MethodCall>[];
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.platform,
(methodCall) async {
calls.add(methodCall);
return null;
});
Comment on lines +46 to +51

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need an addTearDown for this?

addTearDown(() {
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.platform, null);
});

showErrorDialog(context: context, title: title, message: message);
await tester.pump();

check(calls).single.isMethodCall(
'HapticFeedback.vibrate', arguments: 'HapticFeedbackType.errorNotification');
}, variant: const TargetPlatformVariant({TargetPlatform.android, TargetPlatform.iOS}));

testWidgets('user closes error dialog', (tester) async {
await prepare(tester);

Expand Down
Loading