fix review

This commit is contained in:
Salvatore Giordano
2021-06-11 10:31:57 +02:00
parent a6ff8e7039
commit b1201003f5
11 changed files with 51 additions and 70 deletions
@@ -86,11 +86,11 @@ class ChannelImage extends StatelessWidget {
return BetterStreamBuilder<Map<String, dynamic>>(
stream: channel.extraDataStream,
initialData: channel.extraData,
builder: (context, snapshot) {
builder: (context, data) {
String? image;
final chatThemeData = StreamChatTheme.of(context);
if (snapshot.containsKey('image') == true) {
image = snapshot['image'];
if (data.containsKey('image') == true) {
image = data['image'];
} else if (channel.state?.members.length == 2) {
final otherMember = channel.state?.members
.firstWhere((member) => member.user?.id != streamChat.user?.id);
@@ -100,11 +100,11 @@ class ChannelImage extends StatelessWidget {
users[otherMember?.userId] ?? otherMember!.user!)
.distinct(),
initialData: otherMember!.user,
builder: (context, snapshot) => UserAvatar(
builder: (context, user) => UserAvatar(
borderRadius: borderRadius ??
chatThemeData
.channelPreviewTheme.avatarTheme?.borderRadius,
user: snapshot ?? otherMember.user!,
user: user ?? otherMember.user!,
constraints: constraints ??
chatThemeData
.channelPreviewTheme.avatarTheme?.constraints,
@@ -155,7 +155,7 @@ class ChannelImage extends StatelessWidget {
imageUrl: image,
errorWidget: (_, __, ___) => Center(
child: Text(
snapshot.containsKey('name') ? snapshot['name'][0] : '',
data.containsKey('name') ? data['name'][0] : '',
style: TextStyle(
color: chatThemeData.colorTheme.white,
fontWeight: FontWeight.bold,
@@ -28,11 +28,11 @@ class ChannelInfo extends StatelessWidget {
return BetterStreamBuilder<List<Member>>(
stream: channel.state!.membersStream,
initialData: channel.state!.members,
builder: (context, snapshot) => ConnectionStatusBuilder(
builder: (context, data) => ConnectionStatusBuilder(
statusBuilder: (context, status) {
switch (status) {
case ConnectionStatus.connected:
return _buildConnectedTitleState(context, snapshot);
return _buildConnectedTitleState(context, data);
case ConnectionStatus.connecting:
return _buildConnectingTitleState(context);
case ConnectionStatus.disconnected:
@@ -648,7 +648,7 @@ class _ChannelListViewState extends State<ChannelListView> {
),
),
),
builder: (context, snapshot) => snapshot
builder: (context, data) => data
? const Center(
child: Padding(
padding: EdgeInsets.all(16),
@@ -29,8 +29,8 @@ class ChannelName extends StatelessWidget {
return BetterStreamBuilder<Map<String, Object?>>(
stream: channel.extraDataStream,
initialData: channel.extraData,
builder: (context, snapshot) => _buildName(
snapshot,
builder: (context, data) => _buildName(
data,
channel.state?.members,
client,
),
@@ -73,8 +73,8 @@ class ChannelPreview extends StatelessWidget {
return BetterStreamBuilder<bool>(
stream: channel.isMutedStream,
initialData: channel.isMuted,
builder: (context, snapshot) => AnimatedOpacity(
opacity: snapshot ? 0.5 : 1,
builder: (context, data) => AnimatedOpacity(
opacity: data ? 0.5 : 1,
duration: const Duration(milliseconds: 300),
child: ListTile(
visualDensity: VisualDensity.compact,
@@ -108,9 +108,9 @@ class ChannelPreview extends StatelessWidget {
stream: channel.state?.membersStream,
initialData: channel.state?.members,
comparator: const ListEquality().equals,
builder: (context, snapshot) {
if (snapshot?.isEmpty == true ||
snapshot?.any((Member e) =>
builder: (context, members) {
if (members?.isEmpty == true ||
members?.any((Member e) =>
e.user!.id ==
channel.client.state.user?.id) !=
true) {
@@ -165,11 +165,11 @@ class ChannelPreview extends StatelessWidget {
Widget _buildDate(BuildContext context) => BetterStreamBuilder<DateTime?>(
stream: channel.lastMessageAtStream,
initialData: channel.lastMessageAt,
builder: (context, snapshot) {
if (snapshot == null) {
builder: (context, data) {
if (data == null) {
return const Offstage();
}
final lastMessageAt = snapshot.toLocal();
final lastMessageAt = data.toLocal();
String stringDate;
final now = DateTime.now();
@@ -225,9 +225,9 @@ class ChannelPreview extends StatelessWidget {
BetterStreamBuilder<List<Message>?>(
stream: channel.state!.messagesStream,
initialData: channel.state!.messages,
builder: (context, snapshot) {
final lastMessage = snapshot
?.lastWhereOrNull((m) => m.shadowed != true && !m.isDeleted);
builder: (context, data) {
final lastMessage =
data?.lastWhereOrNull((m) => m.shadowed != true && !m.isDeleted);
if (lastMessage == null) {
return const SizedBox();
}
@@ -1,4 +1,3 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
import 'package:stream_chat_flutter_core/stream_chat_flutter_core.dart';
@@ -8,20 +7,16 @@ import 'package:stream_chat_flutter_core/stream_chat_flutter_core.dart';
///
/// The widget will use the closest [StreamChatClient.wsConnectionStatusStream]
/// in case no stream is provided.
class ConnectionStatusBuilder extends StatefulWidget {
class ConnectionStatusBuilder extends StatelessWidget {
/// Creates a new ConnectionStatusBuilder
const ConnectionStatusBuilder({
Key? key,
required this.statusBuilder,
this.initialStatus,
this.connectionStatusStream,
this.errorBuilder,
this.loadingBuilder,
}) : super(key: key);
/// The connection status that will be used to create the initial snapshot.
final ConnectionStatus? initialStatus;
/// The asynchronous computation to which this builder is currently connected.
final Stream<ConnectionStatus>? connectionStatusStream;
@@ -36,32 +31,21 @@ class ConnectionStatusBuilder extends StatefulWidget {
statusBuilder;
@override
_ConnectionStatusBuilderState createState() =>
_ConnectionStatusBuilderState();
}
class _ConnectionStatusBuilderState extends State<ConnectionStatusBuilder> {
late StreamChatClient client;
late Stream<ConnectionStatus> stream;
@override
Widget build(BuildContext context) => BetterStreamBuilder<ConnectionStatus>(
initialData: widget.initialStatus ?? client.wsConnectionStatus,
stream: stream,
loadingBuilder: widget.loadingBuilder,
errorBuilder: (context, error) {
if (widget.errorBuilder != null) {
return widget.errorBuilder!(context, error);
}
return const Offstage();
},
builder: widget.statusBuilder,
);
@override
void didChangeDependencies() {
client = StreamChat.of(context).client;
stream = widget.connectionStatusStream ?? client.wsConnectionStatusStream;
super.didChangeDependencies();
Widget build(BuildContext context) {
final stream = connectionStatusStream ??
StreamChat.of(context).client.wsConnectionStatusStream;
final client = StreamChat.of(context).client;
return BetterStreamBuilder<ConnectionStatus>(
initialData: client.wsConnectionStatus,
stream: stream,
loadingBuilder: loadingBuilder,
errorBuilder: (context, error) {
if (errorBuilder != null) {
return errorBuilder!(context, error);
}
return const Offstage();
},
builder: statusBuilder,
);
}
}
@@ -40,9 +40,6 @@ class InfoTile extends StatelessWidget {
@override
Widget build(BuildContext context) {
final chatThemeData = StreamChatTheme.of(context);
if (!showMessage) {
return child;
}
return PortalEntry(
visible: showMessage,
portalAnchor: tileAnchor ?? Alignment.topCenter,
@@ -1170,9 +1170,9 @@ class _MessageListViewState extends State<MessageListView> {
(messages) =>
messages!.firstWhere((m) => m.id == message.id)),
initialData: message,
builder: (_, snapshot) => StreamChannel(
builder: (_, data) => StreamChannel(
channel: streamChannel!.channel,
child: widget.threadBuilder!(context, snapshot),
child: widget.threadBuilder!(context, data),
),
),
),
@@ -1220,8 +1220,8 @@ class _LoadingIndicator extends StatelessWidget {
child: Text('Error loading messages'),
),
),
builder: (context, snapshot) {
if (!snapshot) {
builder: (context, data) {
if (!data) {
if (!isThreadConversation && direction == QueryDirection.top) {
return const SizedBox(
height: 52,
@@ -49,9 +49,9 @@ class _TypingIndicatorState extends State<TypingIndicator> {
return BetterStreamBuilder<List<User>>(
initialData: channelState.typingEvents,
stream: channelState.typingEventsStream,
builder: (context, snapshot) => AnimatedSwitcher(
builder: (context, data) => AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
child: snapshot.isNotEmpty == true
child: data.isNotEmpty == true
? Padding(
key: const Key('main'),
padding: widget.padding,
@@ -68,7 +68,7 @@ class _TypingIndicatorState extends State<TypingIndicator> {
),
Text(
// ignore: lines_longer_than_80_chars
' ${snapshot[0].name}${snapshot.length == 1 ? '' : ' and ${snapshot.length - 1} more'} ${snapshot.length == 1 ? 'is' : 'are'} typing',
' ${data[0].name}${data.length == 1 ? '' : ' and ${data.length - 1} more'} ${data.length == 1 ? 'is' : 'are'} typing',
maxLines: 1,
style: widget.style,
),
@@ -24,8 +24,8 @@ class UnreadIndicator extends StatelessWidget {
initialData: cid != null
? client.state.channels[cid]?.state?.unreadCount
: client.state.totalUnreadCount,
builder: (context, snapshot) {
if (snapshot == null || snapshot == 0) {
builder: (context, data) {
if (data == null || data == 0) {
return const Offstage();
}
return Material(
@@ -42,7 +42,7 @@ class UnreadIndicator extends StatelessWidget {
),
child: Center(
child: Text(
'${snapshot > 99 ? '99+' : snapshot}',
'${data > 99 ? '99+' : data}',
style: const TextStyle(
fontSize: 11,
color: Colors.white,
@@ -151,8 +151,8 @@ class MessageListCoreState extends State<MessageListCore> {
),
errorBuilder: widget.errorWidgetBuilder,
loadingBuilder: widget.loadingBuilder,
builder: (context, snapshot) {
final messageList = snapshot?.reversed.toList(growable: false) ?? [];
builder: (context, data) {
final messageList = data?.reversed.toList(growable: false) ?? [];
if (messageList.isEmpty && !_isThreadConversation) {
if (_upToDate) {
return widget.emptyBuilder(context);