2020-02-16 09:16:47 +01:00
|
|
|
import 'package:fluffychat/i18n/i18n.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
class SimpleDialogs {
|
|
|
|
final BuildContext context;
|
|
|
|
|
|
|
|
const SimpleDialogs(this.context);
|
|
|
|
|
2020-02-16 09:56:17 +01:00
|
|
|
Future<String> enterText({
|
|
|
|
String titleText,
|
|
|
|
String confirmText,
|
|
|
|
String cancelText,
|
|
|
|
String hintText,
|
|
|
|
String labelText,
|
2020-02-16 11:09:28 +01:00
|
|
|
String prefixText,
|
|
|
|
String suffixText,
|
2020-02-19 16:23:13 +01:00
|
|
|
bool password = false,
|
2020-02-16 09:56:17 +01:00
|
|
|
bool multiLine = false,
|
|
|
|
}) async {
|
|
|
|
final TextEditingController controller = TextEditingController();
|
|
|
|
String input;
|
|
|
|
await showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (c) => AlertDialog(
|
2020-02-16 11:09:28 +01:00
|
|
|
title: Text(titleText ?? I18n.of(context).enterAUsername),
|
2020-02-16 09:56:17 +01:00
|
|
|
content: TextField(
|
|
|
|
controller: controller,
|
|
|
|
autofocus: true,
|
|
|
|
onSubmitted: (s) {
|
|
|
|
input = s;
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
2020-02-16 11:09:28 +01:00
|
|
|
minLines: multiLine ? 3 : 1,
|
|
|
|
maxLines: multiLine ? 3 : 1,
|
2020-02-19 16:23:13 +01:00
|
|
|
obscureText: password,
|
2020-02-16 11:09:28 +01:00
|
|
|
textInputAction: multiLine ? TextInputAction.newline : null,
|
2020-02-16 09:56:17 +01:00
|
|
|
decoration: InputDecoration(
|
|
|
|
hintText: hintText,
|
|
|
|
labelText: labelText,
|
2020-02-16 11:09:28 +01:00
|
|
|
prefixText: prefixText,
|
|
|
|
suffixText: suffixText,
|
2020-02-16 11:36:18 +01:00
|
|
|
prefixStyle: TextStyle(color: Theme.of(context).primaryColor),
|
|
|
|
suffixStyle: TextStyle(color: Theme.of(context).primaryColor),
|
2020-02-16 09:56:17 +01:00
|
|
|
border: OutlineInputBorder(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
actions: <Widget>[
|
|
|
|
FlatButton(
|
2020-02-16 11:36:18 +01:00
|
|
|
child: Text(
|
|
|
|
cancelText?.toUpperCase() ??
|
|
|
|
I18n.of(context).close.toUpperCase(),
|
2020-02-16 09:56:17 +01:00
|
|
|
style: TextStyle(color: Colors.blueGrey)),
|
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
|
|
),
|
|
|
|
FlatButton(
|
|
|
|
child: Text(
|
2020-02-16 11:36:18 +01:00
|
|
|
confirmText?.toUpperCase() ??
|
|
|
|
I18n.of(context).confirm.toUpperCase(),
|
2020-02-16 09:56:17 +01:00
|
|
|
),
|
|
|
|
onPressed: () {
|
|
|
|
input = controller.text;
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
2020-02-16 09:16:47 +01:00
|
|
|
Future<bool> askConfirmation({
|
|
|
|
String titleText,
|
|
|
|
String confirmText,
|
|
|
|
String cancelText,
|
|
|
|
}) async {
|
|
|
|
bool confirmed = false;
|
|
|
|
await showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (c) => AlertDialog(
|
2020-02-16 11:36:18 +01:00
|
|
|
title: Text(titleText ?? I18n.of(context).areYouSure),
|
2020-02-16 09:16:47 +01:00
|
|
|
actions: <Widget>[
|
|
|
|
FlatButton(
|
2020-02-16 11:36:18 +01:00
|
|
|
child: Text(
|
|
|
|
cancelText?.toUpperCase() ??
|
|
|
|
I18n.of(context).close.toUpperCase(),
|
2020-02-16 09:16:47 +01:00
|
|
|
style: TextStyle(color: Colors.blueGrey)),
|
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
|
|
),
|
|
|
|
FlatButton(
|
|
|
|
child: Text(
|
2020-02-16 11:36:18 +01:00
|
|
|
confirmText?.toUpperCase() ??
|
|
|
|
I18n.of(context).confirm.toUpperCase(),
|
2020-02-16 09:16:47 +01:00
|
|
|
),
|
|
|
|
onPressed: () {
|
|
|
|
confirmed = true;
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
return confirmed;
|
|
|
|
}
|
|
|
|
}
|