1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-10-23 06:53:23 +00:00

Add counter on comment form

This commit is contained in:
Pierre HUBERT 2019-05-20 09:20:11 +02:00
parent 073ddd8386
commit 59c3e47419
3 changed files with 35 additions and 26 deletions

View File

@ -325,15 +325,8 @@ class _ConversationScreenState extends State<ConversationScreen> {
maxLengthEnforced: true,
// Show max length only when there is some text already typed
buildCounter: (
BuildContext context, {
@required int currentLength,
@required int maxLength,
@required bool isFocused,
}) =>
currentLength > 0
? Text("$currentLength/$maxLength")
: Container(),
buildCounter: smartInputCounterWidgetBuilder,
enabled: !_isSendingMessage,
controller: _textEditingController,
onChanged: _updatedText,

View File

@ -250,6 +250,11 @@ class _PostTileState extends State<PostTile> {
// Comment input
Expanded(
child: TextField(
// Comment max size
maxLength: 255,
maxLines: null,
buildCounter: smartInputCounterWidgetBuilder,
controller: _commentController,
onChanged: (s) => setState(() {}),
onSubmitted: _canSubmitComment ? (s) => _submitComment() : null,
@ -270,7 +275,8 @@ class _PostTileState extends State<PostTile> {
right: 10,
bottom: 5,
top: 5,
)),
),
),
),
),

View File

@ -153,3 +153,13 @@ Future<bool> showConfirmDialog({
return result != null && result;
}
/// Smart [InputCounterWidgetBuilder] that show text limit only when some
/// text has already been entered by the user
Widget smartInputCounterWidgetBuilder(
BuildContext context, {
@required int currentLength,
@required int maxLength,
@required bool isFocused,
}) =>
currentLength > 0 ? Text("$currentLength/$maxLength") : Container();