Added a flag to control autocorrect in messageinput and a field to provide a custom scroll to bottom builder

This commit is contained in:
Ayush Shekhar
2022-03-07 17:43:00 +05:30
parent 132a78fab4
commit 23c01018ff
2 changed files with 40 additions and 22 deletions
@@ -200,6 +200,7 @@ class MessageInput extends StatefulWidget {
this.customOverlays = const [], this.customOverlays = const [],
this.mentionAllAppUsers = false, this.mentionAllAppUsers = false,
this.shouldKeepFocusAfterMessage, this.shouldKeepFocusAfterMessage,
this.autocorrectEnabled,
}) : assert( }) : assert(
initialMessage == null || editMessage == null, initialMessage == null || editMessage == null,
"Can't provide both `initialMessage` and `editMessage`", "Can't provide both `initialMessage` and `editMessage`",
@@ -322,6 +323,8 @@ class MessageInput extends StatefulWidget {
/// The default behaviour keeps focus until a command is enabled. /// The default behaviour keeps focus until a command is enabled.
final bool? shouldKeepFocusAfterMessage; final bool? shouldKeepFocusAfterMessage;
final bool? autocorrectEnabled;
@override @override
MessageInputState createState() => MessageInputState(); MessageInputState createState() => MessageInputState();
@@ -707,6 +710,7 @@ class MessageInputState extends State<MessageInput> {
textAlignVertical: TextAlignVertical.center, textAlignVertical: TextAlignVertical.center,
decoration: _getInputDecoration(context), decoration: _getInputDecoration(context),
textCapitalization: TextCapitalization.sentences, textCapitalization: TextCapitalization.sentences,
autocorrect: widget.autocorrectEnabled ?? true,
), ),
), ),
], ],
@@ -170,6 +170,7 @@ class MessageListView extends StatefulWidget {
const MessageListView({ const MessageListView({
Key? key, Key? key,
this.showScrollToBottom = true, this.showScrollToBottom = true,
this.scrollToBottomBuilder,
this.messageBuilder, this.messageBuilder,
this.parentMessageBuilder, this.parentMessageBuilder,
this.parentMessage, this.parentMessage,
@@ -242,6 +243,11 @@ class MessageListView extends StatefulWidget {
/// messages and the scroll offset is not zero /// messages and the scroll offset is not zero
final bool showScrollToBottom; final bool showScrollToBottom;
final Widget Function(
int unreadCount,
Future<void> Function(int) scrollToBottomDefaultTapAction,
)? scrollToBottomBuilder;
/// Parent message in case of a thread /// Parent message in case of a thread
final Message? parentMessage; final Message? parentMessage;
@@ -846,30 +852,7 @@ class _MessageListViewState extends State<MessageListView> {
.index; .index;
} }
Widget _buildScrollToBottom() => StreamBuilder<int>( Future<void> scrollToBottomDefaultTapAction(int unreadCount) async {
stream: streamChannel!.channel.state!.unreadCountStream,
builder: (_, snapshot) {
if (snapshot.hasError) {
return const Offstage();
} else if (!snapshot.hasData) {
return const Offstage();
}
final unreadCount = snapshot.data!;
final showUnreadCount = unreadCount > 0 &&
streamChannel!.channel.state!.members.any((e) =>
e.userId ==
streamChannel!.channel.client.state.currentUser!.id);
return Positioned(
bottom: 8,
right: 8,
width: 40,
height: 40,
child: Stack(
clipBehavior: Clip.none,
children: [
FloatingActionButton(
backgroundColor: _streamTheme.colorTheme.barsBg,
onPressed: () async {
if (unreadCount > 0) { if (unreadCount > 0) {
streamChannel!.channel.markRead(); streamChannel!.channel.markRead();
} }
@@ -890,7 +873,38 @@ class _MessageListViewState extends State<MessageListView> {
curve: Curves.easeInOut, curve: Curves.easeInOut,
); );
} }
}, }
Widget _buildScrollToBottom() => StreamBuilder<int>(
stream: streamChannel!.channel.state!.unreadCountStream,
builder: (_, snapshot) {
if (snapshot.hasError) {
return const Offstage();
} else if (!snapshot.hasData) {
return const Offstage();
}
final unreadCount = snapshot.data!;
if (widget.scrollToBottomBuilder != null) {
return widget.scrollToBottomBuilder!(
unreadCount,
scrollToBottomDefaultTapAction,
);
}
final showUnreadCount = unreadCount > 0 &&
streamChannel!.channel.state!.members.any((e) =>
e.userId ==
streamChannel!.channel.client.state.currentUser!.id);
return Positioned(
bottom: 8,
right: 8,
width: 40,
height: 40,
child: Stack(
clipBehavior: Clip.none,
children: [
FloatingActionButton(
backgroundColor: _streamTheme.colorTheme.barsBg,
onPressed: () => scrollToBottomDefaultTapAction(unreadCount),
child: widget.reverse child: widget.reverse
? StreamSvgIcon.down( ? StreamSvgIcon.down(
color: _streamTheme.colorTheme.textHighEmphasis, color: _streamTheme.colorTheme.textHighEmphasis,