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.mentionAllAppUsers = false,
this.shouldKeepFocusAfterMessage,
this.autocorrectEnabled,
}) : assert(
initialMessage == null || editMessage == null,
"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.
final bool? shouldKeepFocusAfterMessage;
final bool? autocorrectEnabled;
@override
MessageInputState createState() => MessageInputState();
@@ -707,6 +710,7 @@ class MessageInputState extends State<MessageInput> {
textAlignVertical: TextAlignVertical.center,
decoration: _getInputDecoration(context),
textCapitalization: TextCapitalization.sentences,
autocorrect: widget.autocorrectEnabled ?? true,
),
),
],
@@ -170,6 +170,7 @@ class MessageListView extends StatefulWidget {
const MessageListView({
Key? key,
this.showScrollToBottom = true,
this.scrollToBottomBuilder,
this.messageBuilder,
this.parentMessageBuilder,
this.parentMessage,
@@ -242,6 +243,11 @@ class MessageListView extends StatefulWidget {
/// messages and the scroll offset is not zero
final bool showScrollToBottom;
final Widget Function(
int unreadCount,
Future<void> Function(int) scrollToBottomDefaultTapAction,
)? scrollToBottomBuilder;
/// Parent message in case of a thread
final Message? parentMessage;
@@ -846,6 +852,29 @@ class _MessageListViewState extends State<MessageListView> {
.index;
}
Future<void> scrollToBottomDefaultTapAction(int unreadCount) async {
if (unreadCount > 0) {
streamChannel!.channel.markRead();
}
if (!_upToDate) {
_bottomPaginationActive = false;
initialAlignment = 0;
initialIndex = 0;
await streamChannel!.reloadChannel();
WidgetsBinding.instance?.addPostFrameCallback((_) {
_scrollController!.jumpTo(index: 0);
});
} else {
_showScrollToBottom.value = false;
_scrollController!.scrollTo(
index: 0,
duration: const Duration(seconds: 1),
curve: Curves.easeInOut,
);
}
}
Widget _buildScrollToBottom() => StreamBuilder<int>(
stream: streamChannel!.channel.state!.unreadCountStream,
builder: (_, snapshot) {
@@ -855,6 +884,12 @@ class _MessageListViewState extends State<MessageListView> {
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 ==
@@ -869,28 +904,7 @@ class _MessageListViewState extends State<MessageListView> {
children: [
FloatingActionButton(
backgroundColor: _streamTheme.colorTheme.barsBg,
onPressed: () async {
if (unreadCount > 0) {
streamChannel!.channel.markRead();
}
if (!_upToDate) {
_bottomPaginationActive = false;
initialAlignment = 0;
initialIndex = 0;
await streamChannel!.reloadChannel();
WidgetsBinding.instance?.addPostFrameCallback((_) {
_scrollController!.jumpTo(index: 0);
});
} else {
_showScrollToBottom.value = false;
_scrollController!.scrollTo(
index: 0,
duration: const Duration(seconds: 1),
curve: Curves.easeInOut,
);
}
},
onPressed: () => scrollToBottomDefaultTapAction(unreadCount),
child: widget.reverse
? StreamSvgIcon.down(
color: _streamTheme.colorTheme.textHighEmphasis,