Skip to content

Commit d6bb115

Browse files
committed
dialog: Add "Learn more"-button param to showErrorDialog
1 parent df66e0a commit d6bb115

12 files changed

+70
-1
lines changed

Diff for: assets/l10n/app_en.arb

+4
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,10 @@
447447
"@dialogClose": {
448448
"description": "Button label in dialogs to close."
449449
},
450+
"errorDialogLearnMore": "Learn more",
451+
"@errorDialogLearnMore": {
452+
"description": "Button label in error dialogs to open a web page with more information."
453+
},
450454
"errorDialogContinue": "OK",
451455
"@errorDialogContinue": {
452456
"description": "Button label in error dialogs to acknowledge the error and close the dialog."

Diff for: lib/generated/l10n/zulip_localizations.dart

+6
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,12 @@ abstract class ZulipLocalizations {
693693
/// **'Close'**
694694
String get dialogClose;
695695

696+
/// Button label in error dialogs to open a web page with more information.
697+
///
698+
/// In en, this message translates to:
699+
/// **'Learn more'**
700+
String get errorDialogLearnMore;
701+
696702
/// Button label in error dialogs to acknowledge the error and close the dialog.
697703
///
698704
/// In en, this message translates to:

Diff for: lib/generated/l10n/zulip_localizations_ar.dart

+3
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,9 @@ class ZulipLocalizationsAr extends ZulipLocalizations {
348348
@override
349349
String get dialogClose => 'Close';
350350

351+
@override
352+
String get errorDialogLearnMore => 'Learn more';
353+
351354
@override
352355
String get errorDialogContinue => 'OK';
353356

Diff for: lib/generated/l10n/zulip_localizations_en.dart

+3
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,9 @@ class ZulipLocalizationsEn extends ZulipLocalizations {
348348
@override
349349
String get dialogClose => 'Close';
350350

351+
@override
352+
String get errorDialogLearnMore => 'Learn more';
353+
351354
@override
352355
String get errorDialogContinue => 'OK';
353356

Diff for: lib/generated/l10n/zulip_localizations_ja.dart

+3
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,9 @@ class ZulipLocalizationsJa extends ZulipLocalizations {
348348
@override
349349
String get dialogClose => 'Close';
350350

351+
@override
352+
String get errorDialogLearnMore => 'Learn more';
353+
351354
@override
352355
String get errorDialogContinue => 'OK';
353356

Diff for: lib/generated/l10n/zulip_localizations_nb.dart

+3
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,9 @@ class ZulipLocalizationsNb extends ZulipLocalizations {
348348
@override
349349
String get dialogClose => 'Close';
350350

351+
@override
352+
String get errorDialogLearnMore => 'Learn more';
353+
351354
@override
352355
String get errorDialogContinue => 'OK';
353356

Diff for: lib/generated/l10n/zulip_localizations_pl.dart

+3
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,9 @@ class ZulipLocalizationsPl extends ZulipLocalizations {
348348
@override
349349
String get dialogClose => 'Zamknij';
350350

351+
@override
352+
String get errorDialogLearnMore => 'Learn more';
353+
351354
@override
352355
String get errorDialogContinue => 'OK';
353356

Diff for: lib/generated/l10n/zulip_localizations_ru.dart

+3
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,9 @@ class ZulipLocalizationsRu extends ZulipLocalizations {
348348
@override
349349
String get dialogClose => 'Закрыть';
350350

351+
@override
352+
String get errorDialogLearnMore => 'Learn more';
353+
351354
@override
352355
String get errorDialogContinue => 'OK';
353356

Diff for: lib/generated/l10n/zulip_localizations_sk.dart

+3
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,9 @@ class ZulipLocalizationsSk extends ZulipLocalizations {
348348
@override
349349
String get dialogClose => 'Zavrieť';
350350

351+
@override
352+
String get errorDialogLearnMore => 'Learn more';
353+
351354
@override
352355
String get errorDialogContinue => 'OK';
353356

Diff for: lib/widgets/dialog.dart

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter/material.dart';
22

33
import '../generated/l10n/zulip_localizations.dart';
4+
import 'actions.dart';
45

56
Widget _dialogActionText(String text) {
67
return Text(
@@ -27,7 +28,8 @@ class DialogStatus {
2728
final Future<void> closed;
2829
}
2930

30-
/// Displays an [AlertDialog] with a dismiss button.
31+
/// Displays an [AlertDialog] with a dismiss button
32+
/// and optional "Learn more" button.
3133
///
3234
/// The [DialogStatus.closed] field of the return value can be used
3335
/// for waiting for the dialog to be closed.
@@ -39,6 +41,7 @@ DialogStatus showErrorDialog({
3941
required BuildContext context,
4042
required String title,
4143
String? message,
44+
Uri? learnMoreButtonUrl,
4245
}) {
4346
final zulipLocalizations = ZulipLocalizations.of(context);
4447
final future = showDialog<void>(
@@ -47,6 +50,10 @@ DialogStatus showErrorDialog({
4750
title: Text(title),
4851
content: message != null ? SingleChildScrollView(child: Text(message)) : null,
4952
actions: [
53+
if (learnMoreButtonUrl != null)
54+
TextButton(
55+
onPressed: () => PlatformActions.launchUrl(context, learnMoreButtonUrl),
56+
child: _dialogActionText(zulipLocalizations.errorDialogLearnMore)),
5057
TextButton(
5158
onPressed: () => Navigator.pop(context),
5259
child: _dialogActionText(zulipLocalizations.errorDialogContinue)),

Diff for: test/widgets/dialog_checks.dart

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Widget checkErrorDialog(WidgetTester tester, {
2323
of: find.byWidget(dialog.content!), matching: find.text(expectedMessage)));
2424
}
2525

26+
// TODO check "Learn more" button?
27+
2628
return tester.widget(
2729
find.descendant(of: find.byWidget(dialog),
2830
matching: find.widgetWithText(TextButton, 'OK')));

Diff for: test/widgets/dialog_test.dart

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import 'package:checks/checks.dart';
2+
import 'package:flutter/widgets.dart';
3+
import 'package:flutter_test/flutter_test.dart';
4+
import 'package:url_launcher/url_launcher.dart';
5+
import 'package:zulip/widgets/dialog.dart';
6+
7+
import '../model/binding.dart';
8+
import 'test_app.dart';
9+
10+
void main() {
11+
TestZulipBinding.ensureInitialized();
12+
13+
group('showErrorDialog', () {
14+
testWidgets('tap "Learn more" button', (tester) async {
15+
addTearDown(testBinding.reset);
16+
await tester.pumpWidget(TestZulipApp());
17+
await tester.pump();
18+
final element = tester.element(find.byType(Placeholder));
19+
20+
showErrorDialog(context: element, title: 'hello',
21+
learnMoreButtonUrl: Uri.parse('foo.example'));
22+
await tester.pump();
23+
await tester.tap(find.text('Learn more'));
24+
check(testBinding.takeLaunchUrlCalls()).single.equals((
25+
url: Uri.parse('foo.example'),
26+
mode: LaunchMode.platformDefault));
27+
});
28+
});
29+
}

0 commit comments

Comments
 (0)