From 0ec6e1c40fe794cc8d13923f9467834a96c98cd9 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Fri, 10 Dec 2021 15:15:58 +0100 Subject: [PATCH] minor updates --- .../lib/src/message_input/message_input.dart | 4 +- .../lib/src/message_input_controller.dart | 50 ++++++++++++------- .../stream_chat_flutter_core/pubspec.yaml | 2 +- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/packages/stream_chat_flutter/lib/src/message_input/message_input.dart b/packages/stream_chat_flutter/lib/src/message_input/message_input.dart index 56bedd57..5a3e51e8 100644 --- a/packages/stream_chat_flutter/lib/src/message_input/message_input.dart +++ b/packages/stream_chat_flutter/lib/src/message_input/message_input.dart @@ -419,9 +419,9 @@ class MessageInputState extends State { @override Widget build(BuildContext context) { - Widget child = ValueListenableBuilder( + Widget child = MessageValueListenableBuilder( valueListenable: messageInputController, - builder: (context, value, wid) => DecoratedBox( + builder: (context, value, _) => DecoratedBox( decoration: BoxDecoration( color: _messageInputTheme.inputBackgroundColor, ), diff --git a/packages/stream_chat_flutter_core/lib/src/message_input_controller.dart b/packages/stream_chat_flutter_core/lib/src/message_input_controller.dart index 0c6a8719..59dfbff7 100644 --- a/packages/stream_chat_flutter_core/lib/src/message_input_controller.dart +++ b/packages/stream_chat_flutter_core/lib/src/message_input_controller.dart @@ -4,6 +4,10 @@ import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:stream_chat/stream_chat.dart'; +/// A value listenable builder related to a [Message] +typedef MessageValueListenableBuilder = ValueListenableBuilder; + +/// A function that returns true if the message is valid and can be sent. typedef MessageValidator = bool Function(Message message); /// Controller for storing and mutating a [Message] value. @@ -81,21 +85,24 @@ class MessageInputController extends ValueNotifier { } } - /// + /// Returns the current message associated with this controller. + Message get message => value; + + /// Returns the controller of the text field linked to this controller. TextEditingController get textEditingController => _textEditingController; final TextEditingController _textEditingController; - /// + /// Returns the text of the message. String get text => _textEditingController.text; Message _initialMessage; - /// + /// Sets the message. set message(Message message) { value = message; } - /// + /// Sets a command for the message. set command(Command command) { value = value.copyWith( command: command.name, @@ -103,6 +110,7 @@ class MessageInputController extends ValueNotifier { ); } + /// Sets the text of the message. set text(String newText) { var newTextWithCommand = newText; if (value.command != null) { @@ -113,79 +121,83 @@ class MessageInputController extends ValueNotifier { value = value.copyWith(text: newTextWithCommand); } - /// + /// Returns the baseOffset of the text field. int get baseOffset => textEditingController.selection.baseOffset; - /// + /// Returns the start of the selection of the text field. int get selectionStart => textEditingController.selection.start; + /// Sets the showInChannel flag of the message. set showInChannel(bool newValue) { value = value.copyWith(showInChannel: newValue); } - /// + /// Returns true if the message is in a thread and + /// should be shown in the main channel as well. bool get showInChannel => value.showInChannel ?? false; - /// + /// Returns the attachments of the message. List get attachments => value.attachments; + /// Sets the list of [attachments] for the message. set attachments(List attachments) { value = value.copyWith(attachments: attachments); } - /// + /// Adds a new attachment to the message. void addAttachment(Attachment attachment) { attachments = [...attachments, attachment]; } - /// + /// Adds a new attachment at the specified [index]. void addAttachmentAt(int index, Attachment attachment) { attachments = [...attachments]..insert(index, attachment); } - /// + /// Removes the specified [attachment] from the message. void removeAttachment(Attachment attachment) { attachments = [...attachments]..remove(attachment); } - /// + /// Remove the attachment with the given [attachmentId]. void removeAttachmentById(String attachmentId) { attachments = [...attachments]..removeWhere((it) => it.id == attachmentId); } - /// + /// Removes the attachment at the given [index]. void removeAttachmentAt(int index) { attachments = [...attachments]..removeAt(index); } - /// + /// Clears the message attachments. void clearAttachments() { attachments = []; } - /// + /// Returns the list of mentioned users in the message. List get mentionedUsers => value.mentionedUsers; + /// Sets the mentioned users. set mentionedUsers(List users) { value = value.copyWith(mentionedUsers: users); } - /// + /// Adds a user to the list of mentioned users. void addMentionedUser(User user) { mentionedUsers = [...mentionedUsers, user]; } - /// + /// Removes the specified [user] from the mentioned users list. void removeMentionedUser(User user) { mentionedUsers = [...mentionedUsers]..remove(user); } - /// + /// Removes the mentioned user with the given [userId]. void removeMentionedUserById(String userId) { mentionedUsers = [...mentionedUsers]..removeWhere((it) => it.id == userId); } - /// + /// Removes all mentioned users from the message. void clearMentionedUsers() { mentionedUsers = []; } diff --git a/packages/stream_chat_flutter_core/pubspec.yaml b/packages/stream_chat_flutter_core/pubspec.yaml index 1b1734be..fb9307c1 100644 --- a/packages/stream_chat_flutter_core/pubspec.yaml +++ b/packages/stream_chat_flutter_core/pubspec.yaml @@ -6,7 +6,7 @@ repository: https://github.com/GetStream/stream-chat-flutter issue_tracker: https://github.com/GetStream/stream-chat-flutter/issues environment: - sdk: '>=2.12.0 <3.0.0' + sdk: '>=2.14.0 <3.0.0' flutter: ">=1.17.0" dependencies: