mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 21:09:21 +00:00
Improve update message dialog
This commit is contained in:
parent
f70717a987
commit
ec4ca238de
@ -2,6 +2,7 @@ import 'dart:async';
|
|||||||
|
|
||||||
import 'package:comunic/helpers/conversations_helper.dart';
|
import 'package:comunic/helpers/conversations_helper.dart';
|
||||||
import 'package:comunic/helpers/events_helper.dart';
|
import 'package:comunic/helpers/events_helper.dart';
|
||||||
|
import 'package:comunic/helpers/server_config_helper.dart';
|
||||||
import 'package:comunic/helpers/users_helper.dart';
|
import 'package:comunic/helpers/users_helper.dart';
|
||||||
import 'package:comunic/lists/conversation_messages_list.dart';
|
import 'package:comunic/lists/conversation_messages_list.dart';
|
||||||
import 'package:comunic/lists/users_list.dart';
|
import 'package:comunic/lists/users_list.dart';
|
||||||
@ -440,7 +441,12 @@ class _ConversationScreenState extends SafeState<ConversationScreen> {
|
|||||||
title: tr("Update message"),
|
title: tr("Update message"),
|
||||||
message: tr("Please enter new message content:"),
|
message: tr("Please enter new message content:"),
|
||||||
defaultValue: message.message.content,
|
defaultValue: message.message.content,
|
||||||
hint: tr("New message"));
|
hint: tr("New message"),
|
||||||
|
minLength:
|
||||||
|
ServerConfigurationHelper.config.conversationsPolicy.minMessageLen,
|
||||||
|
maxLength:
|
||||||
|
ServerConfigurationHelper.config.conversationsPolicy.maxMessageLen,
|
||||||
|
);
|
||||||
|
|
||||||
if (newContent == null) return;
|
if (newContent == null) return;
|
||||||
|
|
||||||
|
@ -93,6 +93,7 @@ Future<String> askUserString({
|
|||||||
@required String defaultValue,
|
@required String defaultValue,
|
||||||
@required String hint,
|
@required String hint,
|
||||||
int maxLength = 200,
|
int maxLength = 200,
|
||||||
|
int minLength = 1,
|
||||||
}) async {
|
}) async {
|
||||||
assert(context != null);
|
assert(context != null);
|
||||||
assert(title != null);
|
assert(title != null);
|
||||||
@ -105,19 +106,58 @@ Future<String> askUserString({
|
|||||||
|
|
||||||
final confirm = await showDialog<bool>(
|
final confirm = await showDialog<bool>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (c) => AlertDialog(
|
builder: (c) => _InputTextDialog(
|
||||||
title: Text(title),
|
title: title,
|
||||||
|
message: message,
|
||||||
|
controller: controller,
|
||||||
|
maxLength: maxLength,
|
||||||
|
minLength: minLength,
|
||||||
|
hint: hint,
|
||||||
|
));
|
||||||
|
|
||||||
|
if (confirm == null || !confirm) return null;
|
||||||
|
|
||||||
|
return controller.text;
|
||||||
|
}
|
||||||
|
|
||||||
|
class _InputTextDialog extends StatefulWidget {
|
||||||
|
final String title;
|
||||||
|
final String message;
|
||||||
|
final TextEditingController controller;
|
||||||
|
final int maxLength;
|
||||||
|
final int minLength;
|
||||||
|
final String hint;
|
||||||
|
|
||||||
|
const _InputTextDialog({
|
||||||
|
Key key,
|
||||||
|
@required this.title,
|
||||||
|
@required this.message,
|
||||||
|
@required this.controller,
|
||||||
|
@required this.maxLength,
|
||||||
|
@required this.minLength,
|
||||||
|
@required this.hint,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
__InputTextDialogState createState() => __InputTextDialogState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class __InputTextDialogState extends State<_InputTextDialog> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext c) => AlertDialog(
|
||||||
|
title: Text(widget.title),
|
||||||
content: AutoSizeDialogContentWidget(
|
content: AutoSizeDialogContentWidget(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text(message),
|
Text(widget.message),
|
||||||
TextField(
|
TextField(
|
||||||
controller: controller,
|
controller: widget.controller,
|
||||||
maxLines: null,
|
maxLines: null,
|
||||||
maxLength: maxLength,
|
maxLength: widget.maxLength,
|
||||||
keyboardType: TextInputType.text,
|
keyboardType: TextInputType.text,
|
||||||
|
onChanged: (s) => setState(() {}),
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: hint,
|
labelText: widget.hint,
|
||||||
alignLabelWithHint: true,
|
alignLabelWithHint: true,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -131,14 +171,12 @@ Future<String> askUserString({
|
|||||||
),
|
),
|
||||||
FlatButton(
|
FlatButton(
|
||||||
child: Text(tr("OK")),
|
child: Text(tr("OK")),
|
||||||
onPressed: () => Navigator.pop(c, true),
|
onPressed: widget.controller.text.length >= widget.minLength
|
||||||
|
? () => Navigator.pop(c, true)
|
||||||
|
: null,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
));
|
);
|
||||||
|
|
||||||
if (confirm == null || !confirm) return null;
|
|
||||||
|
|
||||||
return controller.text;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Show an alert dialog to get user confirmation for something
|
/// Show an alert dialog to get user confirmation for something
|
||||||
|
Loading…
Reference in New Issue
Block a user