Skip to content

Commit 83a3477

Browse files
committed
Add showTextAnswerDialog
1 parent e09d593 commit 83a3477

File tree

6 files changed

+104
-26
lines changed

6 files changed

+104
-26
lines changed

example/lib/pages/text_input_dialog_page.dart

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class TextInputDialogPage extends StatelessWidget {
3636
textFields: const [
3737
DialogTextField(),
3838
],
39-
titleLabel: 'Hello',
39+
title: 'Hello',
4040
);
4141
logger.info(text);
4242
},
@@ -49,8 +49,8 @@ class TextInputDialogPage extends StatelessWidget {
4949
textFields: const [
5050
DialogTextField(),
5151
],
52-
titleLabel: 'Hello',
53-
messageLabel: 'This is a message',
52+
title: 'Hello',
53+
message: 'This is a message',
5454
);
5555
logger.info(text);
5656
},
@@ -70,12 +70,35 @@ class TextInputDialogPage extends StatelessWidget {
7070
obscureText: true,
7171
),
7272
],
73-
titleLabel: 'Hello',
74-
messageLabel: 'This is a message',
73+
title: 'Hello',
74+
message: 'This is a message',
7575
);
7676
logger.info(text);
7777
},
7878
),
79+
ListTile(
80+
title: const Text('TextAnswerDialog'),
81+
onTap: () async {
82+
final ok = await showTextAnswerDialog(
83+
context: context,
84+
keyword: 'Flutter',
85+
title: 'What\'s the best mobile application framework?',
86+
message: 'Input answer and press OK',
87+
hintText: 'Start with "F"',
88+
retryTitle: 'Incorrect',
89+
retryMessage: 'Retry?',
90+
retryOkLabel: 'Retry',
91+
);
92+
print('ok: $ok');
93+
if (!ok) {
94+
return;
95+
}
96+
await showOkAlertDialog(
97+
context: context,
98+
title: 'That\'s right👍',
99+
);
100+
},
101+
),
79102
],
80103
),
81104
);

lib/adaptive_dialog.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export 'src/adaptive_style.dart';
22
export 'src/alert_dialog/alert_dialog.dart';
33
export 'src/modal_action_sheet/modal_action_sheet.dart';
4+
export 'src/text_input_dialog/text_answer_dialog.dart';
45
export 'src/text_input_dialog/text_input_dialog.dart';

lib/src/text_input_dialog/cupertino_text_input_dialog.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ import 'package:adaptive_dialog/src/extensions/extensions.dart';
66
class CupertinoTextInputDialog extends StatefulWidget {
77
const CupertinoTextInputDialog({
88
@required this.textFields,
9-
this.titleLabel,
9+
this.title,
10+
this.message,
1011
this.okLabel,
1112
this.cancelLabel,
12-
this.messageLabel,
1313
this.style = AdaptiveStyle.adaptive,
1414
});
1515
@override
1616
_CupertinoTextInputDialogState createState() =>
1717
_CupertinoTextInputDialogState();
1818

1919
final List<DialogTextField> textFields;
20-
final String titleLabel;
20+
final String title;
21+
final String message;
2122
final String okLabel;
2223
final String cancelLabel;
23-
final String messageLabel;
2424
final AdaptiveStyle style;
2525
}
2626

@@ -51,8 +51,7 @@ class _CupertinoTextInputDialogState extends State<CupertinoTextInputDialog> {
5151
_textControllers.map((c) => c.text).toList(),
5252
);
5353
void cancel() => navigator.pop();
54-
final titleText =
55-
widget.titleLabel == null ? null : Text(widget.titleLabel);
54+
final titleText = widget.title == null ? null : Text(widget.title);
5655
final okText = Text(
5756
widget.okLabel ?? MaterialLocalizations.of(context).okButtonLabel,
5857
);
@@ -92,7 +91,7 @@ class _CupertinoTextInputDialogState extends State<CupertinoTextInputDialog> {
9291
content: Column(
9392
mainAxisSize: MainAxisSize.min,
9493
children: <Widget>[
95-
if (widget.messageLabel != null) Text(widget.messageLabel),
94+
if (widget.message != null) Text(widget.message),
9695
const SizedBox(height: 22),
9796
..._textControllers.mapWithIndex(
9897
(c, i) {

lib/src/text_input_dialog/material_text_input_dialog.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ import 'package:adaptive_dialog/src/extensions/extensions.dart';
55
class MaterialTextInputDialog extends StatefulWidget {
66
const MaterialTextInputDialog({
77
@required this.textFields,
8-
this.titleLabel,
8+
this.title,
9+
this.message,
910
this.okLabel,
1011
this.cancelLabel,
11-
this.messageLabel,
1212
this.style = AdaptiveStyle.adaptive,
1313
});
1414
@override
1515
_MaterialTextInputDialogState createState() =>
1616
_MaterialTextInputDialogState();
1717

1818
final List<DialogTextField> textFields;
19-
final String titleLabel;
19+
final String title;
20+
final String message;
2021
final String okLabel;
2122
final String cancelLabel;
22-
final String messageLabel;
2323
final AdaptiveStyle style;
2424
}
2525

@@ -50,8 +50,7 @@ class _MaterialTextInputDialogState extends State<MaterialTextInputDialog> {
5050
_textControllers.map((c) => c.text).toList(),
5151
);
5252
void cancel() => navigator.pop();
53-
final titleText =
54-
widget.titleLabel == null ? null : Text(widget.titleLabel);
53+
final titleText = widget.title == null ? null : Text(widget.title);
5554
final okText = Text(
5655
widget.okLabel ?? MaterialLocalizations.of(context).okButtonLabel,
5756
);
@@ -61,13 +60,13 @@ class _MaterialTextInputDialogState extends State<MaterialTextInputDialog> {
6160
mainAxisSize: MainAxisSize.min,
6261
crossAxisAlignment: CrossAxisAlignment.start,
6362
children: [
64-
if (widget.messageLabel != null)
63+
if (widget.message != null)
6564
Flexible(
6665
child: Padding(
6766
padding: const EdgeInsets.only(bottom: 8),
6867
child: Scrollbar(
6968
child: SingleChildScrollView(
70-
child: Text(widget.messageLabel),
69+
child: Text(widget.message),
7170
),
7271
),
7372
),
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import 'package:adaptive_dialog/adaptive_dialog.dart';
2+
import 'package:flutter/material.dart';
3+
4+
Future<bool> showTextAnswerDialog({
5+
@required BuildContext context,
6+
@required String keyword,
7+
String title,
8+
String message,
9+
String okLabel,
10+
String cancelLabel,
11+
String hintText,
12+
String retryTitle,
13+
String retryMessage,
14+
String retryOkLabel,
15+
String retryCancelLabel,
16+
AdaptiveStyle style = AdaptiveStyle.adaptive,
17+
}) async {
18+
final texts = await showTextInputDialog(
19+
context: context,
20+
textFields: [
21+
DialogTextField(hintText: hintText),
22+
],
23+
title: title,
24+
message: message,
25+
okLabel: okLabel,
26+
cancelLabel: cancelLabel,
27+
style: style,
28+
);
29+
final text = texts == null ? null : texts[0];
30+
if (text == keyword) {
31+
return true;
32+
}
33+
final result = showOkCancelAlertDialog(
34+
context: context,
35+
title: retryTitle,
36+
message: retryMessage,
37+
okLabel: retryOkLabel,
38+
cancelLabel: retryCancelLabel,
39+
defaultType: OkCancelAlertDefaultType.ok,
40+
);
41+
return result == OkCancelResult.ok
42+
? showTextAnswerDialog(
43+
context: context,
44+
keyword: keyword,
45+
message: message,
46+
okLabel: okLabel,
47+
cancelLabel: cancelLabel,
48+
hintText: hintText,
49+
retryTitle: retryTitle,
50+
retryMessage: retryMessage,
51+
retryOkLabel: retryOkLabel,
52+
retryCancelLabel: retryCancelLabel,
53+
style: style,
54+
)
55+
: Future.value(false);
56+
}

lib/src/text_input_dialog/text_input_dialog.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import 'material_text_input_dialog.dart';
88
Future<List<String>> showTextInputDialog({
99
@required BuildContext context,
1010
@required List<DialogTextField> textFields,
11-
String titleLabel,
11+
String title,
12+
String message,
1213
String okLabel,
1314
String cancelLabel,
14-
String messageLabel,
1515
AdaptiveStyle style = AdaptiveStyle.adaptive,
1616
}) {
1717
final theme = Theme.of(context);
@@ -20,21 +20,21 @@ Future<List<String>> showTextInputDialog({
2020
context: context,
2121
builder: (context) => CupertinoTextInputDialog(
2222
textFields: textFields,
23-
titleLabel: titleLabel,
23+
title: title,
24+
message: message,
2425
okLabel: okLabel,
2526
cancelLabel: cancelLabel,
26-
messageLabel: messageLabel,
2727
style: style,
2828
),
2929
)
3030
: showDialog(
3131
context: context,
3232
builder: (context) => MaterialTextInputDialog(
3333
textFields: textFields,
34-
titleLabel: titleLabel,
34+
title: title,
35+
message: message,
3536
okLabel: okLabel,
3637
cancelLabel: cancelLabel,
37-
messageLabel: messageLabel,
3838
style: style,
3939
),
4040
);

0 commit comments

Comments
 (0)