add datedivider builder
This commit is contained in:
+30
-40
@@ -1,18 +1,15 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:jiffy/jiffy.dart';
|
import 'package:jiffy/jiffy.dart';
|
||||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
|
||||||
|
|
||||||
/// It shows a date divider depending on the date difference
|
/// It shows a date divider depending on the date difference
|
||||||
class DateDivider extends StatelessWidget {
|
class DateDivider extends StatelessWidget {
|
||||||
|
final DateTime dateTime;
|
||||||
|
|
||||||
const DateDivider({
|
const DateDivider({
|
||||||
Key key,
|
Key key,
|
||||||
@required this.nextMessage,
|
@required this.dateTime,
|
||||||
@required this.messageWidget,
|
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
final Message nextMessage;
|
|
||||||
final Widget messageWidget;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final divider = Expanded(
|
final divider = Expanded(
|
||||||
@@ -22,7 +19,7 @@ class DateDivider extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
final createdAt = Jiffy(nextMessage.createdAt.toLocal());
|
final createdAt = Jiffy(dateTime);
|
||||||
final now = DateTime.now();
|
final now = DateTime.now();
|
||||||
final hourInfo = createdAt.format('h:mm a');
|
final hourInfo = createdAt.format('h:mm a');
|
||||||
|
|
||||||
@@ -46,46 +43,39 @@ class DateDivider extends StatelessWidget {
|
|||||||
dayInfo = createdAt.format('dd/MM/yyyy').toUpperCase();
|
dayInfo = createdAt.format('dd/MM/yyyy').toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Column(
|
return Padding(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
padding: const EdgeInsets.only(top: 24.0),
|
||||||
children: <Widget>[
|
child: Row(
|
||||||
messageWidget,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
Padding(
|
children: <Widget>[
|
||||||
padding: const EdgeInsets.only(top: 24.0),
|
divider,
|
||||||
child: Row(
|
Padding(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
padding: const EdgeInsets.symmetric(horizontal: 32.0),
|
||||||
children: <Widget>[
|
child: Text.rich(
|
||||||
divider,
|
TextSpan(
|
||||||
Padding(
|
children: [
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 32.0),
|
|
||||||
child: Text.rich(
|
|
||||||
TextSpan(
|
TextSpan(
|
||||||
children: [
|
text: dayInfo,
|
||||||
TextSpan(
|
|
||||||
text: dayInfo,
|
|
||||||
style: TextStyle(
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
TextSpan(text: ' AT'),
|
|
||||||
TextSpan(text: ' $hourInfo'),
|
|
||||||
],
|
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.normal,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
style: TextStyle(
|
TextSpan(text: ' AT'),
|
||||||
fontSize: 10,
|
TextSpan(text: ' $hourInfo'),
|
||||||
color:
|
],
|
||||||
Theme.of(context).textTheme.title.color.withOpacity(.5),
|
style: TextStyle(
|
||||||
),
|
fontWeight: FontWeight.normal,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
divider,
|
style: TextStyle(
|
||||||
],
|
fontSize: 10,
|
||||||
|
color: Theme.of(context).textTheme.title.color.withOpacity(.5),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
divider,
|
||||||
],
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -719,6 +719,7 @@ class _MessageInputState extends State<MessageInput> {
|
|||||||
},
|
},
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
Icons.send,
|
Icons.send,
|
||||||
|
color: StreamChatTheme.of(context).accentColor,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ class MessageListView extends StatefulWidget {
|
|||||||
this.onMentionTap,
|
this.onMentionTap,
|
||||||
this.onMessageActions,
|
this.onMessageActions,
|
||||||
this.attachmentBuilders,
|
this.attachmentBuilders,
|
||||||
|
this.dateDividerBuilder,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
/// Function used to build a custom message widget
|
/// Function used to build a custom message widget
|
||||||
@@ -102,6 +103,9 @@ class MessageListView extends StatefulWidget {
|
|||||||
/// Map that defines a builder for an attachment type
|
/// Map that defines a builder for an attachment type
|
||||||
final Map<String, AttachmentBuilder> attachmentBuilders;
|
final Map<String, AttachmentBuilder> attachmentBuilders;
|
||||||
|
|
||||||
|
/// Builder used to render date dividers
|
||||||
|
final Widget Function(DateTime) dateDividerBuilder;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_MessageListViewState createState() => _MessageListViewState();
|
_MessageListViewState createState() => _MessageListViewState();
|
||||||
}
|
}
|
||||||
@@ -232,9 +236,17 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
if (nextMessage != null &&
|
if (nextMessage != null &&
|
||||||
!Jiffy(message.createdAt.toLocal())
|
!Jiffy(message.createdAt.toLocal())
|
||||||
.isSame(nextMessage.createdAt.toLocal(), Units.DAY)) {
|
.isSame(nextMessage.createdAt.toLocal(), Units.DAY)) {
|
||||||
return DateDivider(
|
return Column(
|
||||||
messageWidget: messageWidget,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
nextMessage: nextMessage,
|
children: <Widget>[
|
||||||
|
messageWidget,
|
||||||
|
widget.dateDividerBuilder != null
|
||||||
|
? widget
|
||||||
|
.dateDividerBuilder(nextMessage.createdAt.toLocal())
|
||||||
|
: DateDivider(
|
||||||
|
dateTime: nextMessage.createdAt.toLocal(),
|
||||||
|
),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ class _MessageWidgetState extends State<MessageWidget>
|
|||||||
Widget _buildThreadIndicator(BuildContext context) {
|
Widget _buildThreadIndicator(BuildContext context) {
|
||||||
if (widget.message?.replyCount != null && widget.message.replyCount > 0) {
|
if (widget.message?.replyCount != null && widget.message.replyCount > 0) {
|
||||||
return ReplyIndicator(
|
return ReplyIndicator(
|
||||||
onTap: widget.isParent
|
onTap: !widget.isParent
|
||||||
? () {
|
? () {
|
||||||
widget.onThreadTap(widget.message);
|
widget.onThreadTap(widget.message);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user