add messagelist typing indicator

This commit is contained in:
Salvatore Giordano
2020-11-25 12:43:42 +01:00
parent 24c5e39bda
commit 71123fbafb
5 changed files with 67 additions and 26 deletions
+24 -2
View File
@@ -223,17 +223,39 @@ class ChannelPage extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: ChannelHeader(), appBar: ChannelHeader(
showTypingIndicator: false,
),
body: Column( body: Column(
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
child: MessageListView( child: Stack(
children: <Widget>[
MessageListView(
threadBuilder: (_, parentMessage) { threadBuilder: (_, parentMessage) {
return ThreadPage( return ThreadPage(
parent: parentMessage, parent: parentMessage,
); );
}, },
), ),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Container(
alignment: Alignment.centerLeft,
color: Color(0xffFCFCFC).withOpacity(.9),
child: TypingIndicator(
alignment: Alignment.centerLeft,
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 4,
),
),
),
),
],
),
), ),
MessageInput(), MessageInput(),
], ],
+1 -1
View File
@@ -1,6 +1,6 @@
name: example name: example
description: A new Flutter project. description: A new Flutter project.
version: 1.0.74+76 version: 1.0.75+77
environment: environment:
sdk: ">=2.2.2 <3.0.0" sdk: ">=2.2.2 <3.0.0"
+5
View File
@@ -64,12 +64,16 @@ class ChannelHeader extends StatelessWidget implements PreferredSizeWidget {
/// Callback to call when the image is tapped. /// Callback to call when the image is tapped.
final VoidCallback onImageTap; final VoidCallback onImageTap;
/// If true the typing indicator will be rendered if a user is typing
final bool showTypingIndicator;
/// Creates a channel header /// Creates a channel header
ChannelHeader({ ChannelHeader({
Key key, Key key,
this.showBackButton = true, this.showBackButton = true,
this.onBackPressed, this.onBackPressed,
this.onTitleTap, this.onTitleTap,
this.showTypingIndicator = true,
this.onImageTap, this.onImageTap,
}) : preferredSize = Size.fromHeight(kToolbarHeight), }) : preferredSize = Size.fromHeight(kToolbarHeight),
super(key: key); super(key: key);
@@ -116,6 +120,7 @@ class ChannelHeader extends StatelessWidget implements PreferredSizeWidget {
), ),
SizedBox(height: 2), SizedBox(height: 2),
ChannelInfo( ChannelInfo(
showTypingIndicator: showTypingIndicator,
channel: channel, channel: channel,
textStyle: textStyle:
StreamChatTheme.of(context).channelPreviewTheme.subtitle, StreamChatTheme.of(context).channelPreviewTheme.subtitle,
+8
View File
@@ -8,10 +8,14 @@ class ChannelInfo extends StatelessWidget {
/// The style of the text displayed /// The style of the text displayed
final TextStyle textStyle; final TextStyle textStyle;
/// If true the typing indicator will be rendered if a user is typing
final bool showTypingIndicator;
const ChannelInfo({ const ChannelInfo({
Key key, Key key,
@required this.channel, @required this.channel,
this.textStyle, this.textStyle,
this.showTypingIndicator = true,
}) : super(key: key); }) : super(key: key);
@override @override
@@ -75,6 +79,10 @@ class ChannelInfo extends StatelessWidget {
} }
} }
if (!showTypingIndicator) {
return alternativeWidget;
}
return TypingIndicator( return TypingIndicator(
alignment: Alignment.center, alignment: Alignment.center,
alternativeWidget: alternativeWidget, alternativeWidget: alternativeWidget,
+9 -3
View File
@@ -12,6 +12,7 @@ class TypingIndicator extends StatelessWidget {
this.alternativeWidget, this.alternativeWidget,
this.style, this.style,
this.alignment = Alignment.centerLeft, this.alignment = Alignment.centerLeft,
this.padding = const EdgeInsets.all(0),
}) : super(key: key); }) : super(key: key);
/// Style of the text widget /// Style of the text widget
@@ -23,6 +24,9 @@ class TypingIndicator extends StatelessWidget {
/// Widget built when no typings is happening /// Widget built when no typings is happening
final Widget alternativeWidget; final Widget alternativeWidget;
/// The padding of this widget
final EdgeInsets padding;
final Alignment alignment; final Alignment alignment;
@override @override
@@ -36,16 +40,17 @@ class TypingIndicator extends StatelessWidget {
return AnimatedSwitcher( return AnimatedSwitcher(
duration: Duration(milliseconds: 300), duration: Duration(milliseconds: 300),
child: snapshot.data?.isNotEmpty == true child: snapshot.data?.isNotEmpty == true
? Align( ? Padding(
padding: padding,
child: Align(
key: Key('typings'), key: Key('typings'),
alignment: alignment, alignment: alignment,
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.min,
children: [ children: [
Lottie.asset( Lottie.asset(
'animations/typing_dots.json', 'animations/typing_dots.json',
package: 'stream_chat_flutter', package: 'stream_chat_flutter',
alignment: Alignment.center,
height: 4, height: 4,
), ),
Text( Text(
@@ -55,6 +60,7 @@ class TypingIndicator extends StatelessWidget {
), ),
], ],
), ),
),
) )
: Align( : Align(
key: Key('alternative'), key: Key('alternative'),