Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: SebastienBtr/Dash-Chat-2
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: xozero/Dash-Chat-2
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 5 commits
  • 3 files changed
  • 1 contributor

Commits on Dec 6, 2022

  1. Minor fixes

    instance01 committed Dec 6, 2022
    Copy the full SHA
    90d1b93 View commit details
  2. Scroll correctly now

    instance01 committed Dec 6, 2022
    Copy the full SHA
    a3f906b View commit details

Commits on Dec 8, 2022

  1. Copy the full SHA
    4ca032a View commit details

Commits on Dec 10, 2022

  1. Actually let's do 1000

    instance01 committed Dec 10, 2022
    Copy the full SHA
    36656e2 View commit details

Commits on Dec 14, 2022

  1. Weird

    instance01 committed Dec 14, 2022
    Copy the full SHA
    59e47b4 View commit details
Showing with 139 additions and 137 deletions.
  1. +2 −2 lib/src/widgets/message_list/default_scroll_to_bottom.dart
  2. +107 −105 lib/src/widgets/message_list/message_list.dart
  3. +30 −30 pubspec.lock
4 changes: 2 additions & 2 deletions lib/src/widgets/message_list/default_scroll_to_bottom.dart
Original file line number Diff line number Diff line change
@@ -83,8 +83,8 @@ class DefaultScrollToBottom extends StatelessWidget {
onScrollToBottomPress!();
}
scrollController.animateTo(
0.0,
duration: const Duration(milliseconds: 300),
scrollController.position.maxScrollExtent + 1000,
duration: const Duration(milliseconds: 200),
curve: Curves.easeInOut,
);
},
212 changes: 107 additions & 105 deletions lib/src/widgets/message_list/message_list.dart
Original file line number Diff line number Diff line change
@@ -55,111 +55,114 @@ class _MessageListState extends State<MessageList> {
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => FocusScope.of(context).requestFocus(FocusNode()),
child: Stack(
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expanded(
child: ListView.builder(
physics: widget.messageListOptions.scrollPhysics,
controller: scrollController,
reverse: true,
itemCount: widget.messages.length,
itemBuilder: (BuildContext context, int i) {
final ChatMessage? previousMessage =
i < widget.messages.length - 1
? widget.messages[i + 1]
: null;
final ChatMessage? nextMessage =
i > 0 ? widget.messages[i - 1] : null;
final ChatMessage message = widget.messages[i];
final bool isAfterDateSeparator = _shouldShowDateSeparator(
previousMessage, message, widget.messageListOptions);
bool isBeforeDateSeparator = false;
if (nextMessage != null) {
isBeforeDateSeparator = _shouldShowDateSeparator(
message, nextMessage, widget.messageListOptions);
}
return Column(
children: <Widget>[
if (isAfterDateSeparator)
widget.messageListOptions.dateSeparatorBuilder != null
? widget.messageListOptions
.dateSeparatorBuilder!(message.createdAt)
: DefaultDateSeparator(
date: message.createdAt,
messageListOptions: widget.messageListOptions,
),
if (widget.messageOptions.messageRowBuilder !=
null) ...<Widget>[
widget.messageOptions.messageRowBuilder!(
message,
previousMessage,
nextMessage,
isAfterDateSeparator,
isBeforeDateSeparator,
),
] else
MessageRow(
message: widget.messages[i],
nextMessage: nextMessage,
previousMessage: previousMessage,
currentUser: widget.currentUser,
isAfterDateSeparator: isAfterDateSeparator,
isBeforeDateSeparator: isBeforeDateSeparator,
messageOptions: widget.messageOptions,
),
],
);
},
),
),
if (widget.typingUsers != null && widget.typingUsers!.isNotEmpty)
...widget.typingUsers!.map((ChatUser user) {
if (widget.messageListOptions.typingBuilder != null) {
return widget.messageListOptions.typingBuilder!(user);
}
return DefaultTypingBuilder(user: user);
}).toList(),
if (widget.messageListOptions.showFooterBeforeQuickReplies &&
widget.messageListOptions.chatFooterBuilder != null)
widget.messageListOptions.chatFooterBuilder!,
if (widget.messages.isNotEmpty &&
widget.messages.first.quickReplies != null &&
widget.messages.first.quickReplies!.isNotEmpty &&
widget.messages.first.user.id != widget.currentUser.id)
QuickReplies(
quickReplies: widget.messages.first.quickReplies!,
quickReplyOptions: widget.quickReplyOptions,
child: Padding(
padding: EdgeInsets.only(left: 10.0, right: 10.0),
child: Stack(
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expanded(
child: ListView.builder(
physics: widget.messageListOptions.scrollPhysics,
controller: scrollController,
reverse: false,
itemCount: widget.messages.length,
itemBuilder: (BuildContext context, int i) {
final ChatMessage? previousMessage =
i < widget.messages.length - 1
? widget.messages[i + 1]
: null;
final ChatMessage? nextMessage =
i > 0 ? widget.messages[i - 1] : null;
final ChatMessage message = widget.messages[i];
final bool isAfterDateSeparator = _shouldShowDateSeparator(
previousMessage, message, widget.messageListOptions);
bool isBeforeDateSeparator = false;
if (nextMessage != null) {
isBeforeDateSeparator = _shouldShowDateSeparator(
message, nextMessage, widget.messageListOptions);
}
return Column(
children: <Widget>[
if (isAfterDateSeparator)
widget.messageListOptions.dateSeparatorBuilder != null
? widget.messageListOptions
.dateSeparatorBuilder!(message.createdAt)
: DefaultDateSeparator(
date: message.createdAt,
messageListOptions: widget.messageListOptions,
),
if (widget.messageOptions.messageRowBuilder !=
null) ...<Widget>[
widget.messageOptions.messageRowBuilder!(
message,
previousMessage,
nextMessage,
isAfterDateSeparator,
isBeforeDateSeparator,
),
] else
MessageRow(
message: widget.messages[i],
nextMessage: nextMessage,
previousMessage: previousMessage,
currentUser: widget.currentUser,
isAfterDateSeparator: isAfterDateSeparator,
isBeforeDateSeparator: isBeforeDateSeparator,
messageOptions: widget.messageOptions,
),
],
);
},
),
),
if (!widget.messageListOptions.showFooterBeforeQuickReplies &&
widget.messageListOptions.chatFooterBuilder != null)
widget.messageListOptions.chatFooterBuilder!,
],
),
if (isLoadingMore)
Positioned(
top: 8.0,
right: 0,
left: 0,
child: widget.messageListOptions.loadEarlierBuilder ??
const Center(
child: SizedBox(
child: CircularProgressIndicator(),
),
if (widget.typingUsers != null && widget.typingUsers!.isNotEmpty)
...widget.typingUsers!.map((ChatUser user) {
if (widget.messageListOptions.typingBuilder != null) {
return widget.messageListOptions.typingBuilder!(user);
}
return DefaultTypingBuilder(user: user);
}).toList(),
if (widget.messageListOptions.showFooterBeforeQuickReplies &&
widget.messageListOptions.chatFooterBuilder != null)
widget.messageListOptions.chatFooterBuilder!,
if (widget.messages.isNotEmpty &&
widget.messages.first.quickReplies != null &&
widget.messages.first.quickReplies!.isNotEmpty &&
widget.messages.first.user.id != widget.currentUser.id)
QuickReplies(
quickReplies: widget.messages.first.quickReplies!,
quickReplyOptions: widget.quickReplyOptions,
),
if (!widget.messageListOptions.showFooterBeforeQuickReplies &&
widget.messageListOptions.chatFooterBuilder != null)
widget.messageListOptions.chatFooterBuilder!,
],
),
if (!widget.scrollToBottomOptions.disabled && scrollToBottomIsVisible)
widget.scrollToBottomOptions.scrollToBottomBuilder != null
? widget.scrollToBottomOptions
.scrollToBottomBuilder!(scrollController)
: DefaultScrollToBottom(
scrollController: scrollController,
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
textColor: Theme.of(context).primaryColor,
),
],
if (isLoadingMore)
Positioned(
top: 8.0,
right: 0,
left: 0,
child: widget.messageListOptions.loadEarlierBuilder ??
const Center(
child: SizedBox(
child: CircularProgressIndicator(),
),
),
),
if (!widget.scrollToBottomOptions.disabled && scrollToBottomIsVisible)
widget.scrollToBottomOptions.scrollToBottomBuilder != null
? widget.scrollToBottomOptions
.scrollToBottomBuilder!(scrollController)
: DefaultScrollToBottom(
scrollController: scrollController,
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
textColor: Theme.of(context).primaryColor,
),
],
),
),
);
}
@@ -210,8 +213,7 @@ class _MessageListState extends State<MessageList> {
/// show scroll-to-bottom btn and LoadEarlier behaviour
Future<void> _onScroll() async {
bool topReached =
scrollController.offset >= scrollController.position.maxScrollExtent &&
!scrollController.position.outOfRange;
scrollController.offset <= 100;// && !scrollController.position.outOfRange;
if (topReached &&
widget.messageListOptions.onLoadEarlier != null &&
!isLoadingMore) {
@@ -223,7 +225,7 @@ class _MessageListState extends State<MessageList> {
setState(() {
isLoadingMore = false;
});
} else if (scrollController.offset > 200) {
} else if (scrollController.offset < scrollController.position.maxScrollExtent - 200) {
showScrollToBottom();
} else {
hideScrollToBottom();
Loading