Merge branch 'develop' into repo/dart-code-metrics

This commit is contained in:
Sahil Kumar
2021-10-07 18:13:34 +05:30
committed by GitHub
53 changed files with 862 additions and 794 deletions
@@ -10,6 +10,7 @@ class UrlAttachment extends StatelessWidget {
Key? key,
required this.urlAttachment,
required this.hostDisplayName,
required this.messageTheme,
this.textPadding = const EdgeInsets.symmetric(
horizontal: 16,
vertical: 8,
@@ -25,6 +26,9 @@ class UrlAttachment extends StatelessWidget {
/// Padding for text
final EdgeInsets textPadding;
/// [MessageThemeData] for showing image title
final MessageThemeData messageTheme;
@override
Widget build(BuildContext context) {
final chatThemeData = StreamChatTheme.of(context);
@@ -58,7 +62,7 @@ class UrlAttachment extends StatelessWidget {
borderRadius: const BorderRadius.only(
topRight: Radius.circular(16),
),
color: chatThemeData.colorTheme.linkBg,
color: messageTheme.linkBackgroundColor,
),
child: Padding(
padding: const EdgeInsets.only(
@@ -12,7 +12,7 @@ final _emojiChars = Emoji.chars();
extension StringExtension on String {
/// Returns the capitalized string
String capitalize() =>
'${this[0].toUpperCase()}${substring(1).toLowerCase()}';
isNotEmpty ? '${this[0].toUpperCase()}${substring(1).toLowerCase()}' : '';
/// Returns whether the string contains only emoji's or not.
///
@@ -386,6 +386,9 @@ class MessageInputState extends State<MessageInput> {
Timer? _slowModeTimer;
void _startSlowMode() {
if (!mounted) {
return;
}
final channel = StreamChannel.of(context).channel;
final cooldownStartedAt = channel.cooldownStartedAt;
if (cooldownStartedAt != null) {
@@ -170,6 +170,7 @@ class MessageListView extends StatefulWidget {
this.messageListController,
this.reverse = true,
this.paginationLimit = 20,
this.paginationLoadingIndicatorBuilder,
}) : super(key: key);
/// Function used to build a custom message widget
@@ -285,6 +286,9 @@ class MessageListView extends StatefulWidget {
/// Use [ChannelListController.paginateData] pagination.
final MessageListController? messageListController;
/// Builder used to build the loading indicator shown while paginating.
final WidgetBuilder? paginationLoadingIndicatorBuilder;
@override
_MessageListViewState createState() => _MessageListViewState();
}
@@ -294,7 +298,6 @@ class _MessageListViewState extends State<MessageListView> {
void Function(Message)? _onThreadTap;
bool _showScrollToBottom = false;
late final ItemPositionsListener _itemPositionListener;
late final Stream<Iterable<ItemPosition>> _itemPositionStream;
int? _messageListLength;
StreamChannelState? streamChannel;
late StreamChatThemeData _streamTheme;
@@ -576,17 +579,22 @@ class _MessageListViewState extends State<MessageListView> {
}
}
final indicatorBuilder =
widget.paginationLoadingIndicatorBuilder;
if (i == itemCount - 3) {
return _buildLoadingIndicator(
return _loadingIndicator(
streamChannel!,
QueryDirection.top,
indicatorBuilder: indicatorBuilder,
);
}
if (i == 1) {
return _buildLoadingIndicator(
return _loadingIndicator(
streamChannel!,
QueryDirection.bottom,
indicatorBuilder: indicatorBuilder,
);
}
@@ -668,7 +676,8 @@ class _MessageListViewState extends State<MessageListView> {
right: 0,
child: BetterStreamBuilder<Iterable<ItemPosition>>(
initialData: _itemPositionListener.itemPositions.value,
stream: _itemPositionStream,
stream: _valueListenableToStreamAdapter(
_itemPositionListener.itemPositions),
comparator: (a, b) {
if (a == null || b == null) {
return false;
@@ -819,15 +828,17 @@ class _MessageListViewState extends State<MessageListView> {
},
);
Widget _buildLoadingIndicator(
Widget _loadingIndicator(
StreamChannelState streamChannel,
QueryDirection direction,
) =>
QueryDirection direction, {
WidgetBuilder? indicatorBuilder,
}) =>
_LoadingIndicator(
direction: direction,
streamTheme: _streamTheme,
streamChannel: streamChannel,
isThreadConversation: _isThreadConversation,
indicatorBuilder: indicatorBuilder,
);
Widget _buildBottomMessage(
@@ -1197,8 +1208,6 @@ class _MessageListViewState extends State<MessageListView> {
_scrollController = widget.scrollController ?? ItemScrollController();
_itemPositionListener =
widget.itemPositionListener ?? ItemPositionsListener.create();
_itemPositionStream =
_valueListenableToStreamAdapter(_itemPositionListener.itemPositions);
_getOnThreadTap();
super.initState();
@@ -1297,12 +1306,14 @@ class _LoadingIndicator extends StatelessWidget {
required this.isThreadConversation,
required this.direction,
required this.streamChannel,
this.indicatorBuilder,
}) : super(key: key);
final StreamChatThemeData streamTheme;
final bool isThreadConversation;
final QueryDirection direction;
final StreamChannelState streamChannel;
final WidgetBuilder? indicatorBuilder;
@override
Widget build(BuildContext context) {
@@ -1321,12 +1332,13 @@ class _LoadingIndicator extends StatelessWidget {
),
builder: (context, data) {
if (!data) return const Offstage();
return const Center(
child: Padding(
padding: EdgeInsets.all(8),
child: CircularProgressIndicator(),
),
);
return indicatorBuilder?.call(context) ??
const Center(
child: Padding(
padding: EdgeInsets.all(8),
child: CircularProgressIndicator(),
),
);
},
);
}
@@ -7,6 +7,7 @@ import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter_portal/flutter_portal.dart';
import 'package:jiffy/jiffy.dart';
import 'package:stream_chat_flutter/src/attachment/url_attachment.dart';
import 'package:stream_chat_flutter/src/extension.dart';
import 'package:stream_chat_flutter/src/image_group.dart';
import 'package:stream_chat_flutter/src/message_action.dart';
@@ -15,7 +16,6 @@ import 'package:stream_chat_flutter/src/message_reactions_modal.dart';
import 'package:stream_chat_flutter/src/quoted_message_widget.dart';
import 'package:stream_chat_flutter/src/reaction_bubble.dart';
import 'package:stream_chat_flutter/src/theme/themes.dart';
import 'package:stream_chat_flutter/src/url_attachment.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
/// Widget builder for building attachments
@@ -1010,6 +1010,7 @@ class _MessageWidgetState extends State<MessageWidget>
urlAttachment: urlAttachment,
hostDisplayName: hostDisplayName,
textPadding: widget.textPadding,
messageTheme: widget.messageTheme,
);
}
@@ -1348,7 +1349,7 @@ class _MessageWidgetState extends State<MessageWidget>
}
if (hasUrlAttachments) {
return _streamChatTheme.colorTheme.linkBg;
return widget.messageTheme.linkBackgroundColor;
}
if (isOnlyEmoji) {
@@ -285,7 +285,7 @@ class QuotedMessageWidget extends StatelessWidget {
Color? _getBackgroundColor(BuildContext context) {
if (_containsLinkAttachment) {
return StreamChatTheme.of(context).colorTheme.linkBg;
return messageTheme.linkBackgroundColor;
}
return messageTheme.messageBackgroundColor;
}
@@ -223,6 +223,7 @@ class StreamChatThemeData {
messageLinksStyle: TextStyle(
color: accentColor,
),
linkBackgroundColor: colorTheme.linkBg,
),
otherMessageTheme: MessageThemeData(
reactionsBackgroundColor: colorTheme.disabled,
@@ -246,6 +247,7 @@ class StreamChatThemeData {
width: 32,
),
),
linkBackgroundColor: colorTheme.linkBg,
),
messageInputTheme: MessageInputThemeData(
borderRadius: BorderRadius.circular(20),
@@ -18,6 +18,7 @@ class MessageThemeData with Diagnosticable {
this.reactionsMaskColor,
this.avatarTheme,
this.createdAtStyle,
this.linkBackgroundColor,
});
/// Text style for message text
@@ -53,6 +54,9 @@ class MessageThemeData with Diagnosticable {
/// Theme of the avatar
final AvatarThemeData? avatarTheme;
/// Background color for messages with url attachments.
final Color? linkBackgroundColor;
/// Copy with a theme
MessageThemeData copyWith({
TextStyle? messageTextStyle,
@@ -66,6 +70,7 @@ class MessageThemeData with Diagnosticable {
Color? reactionsBackgroundColor,
Color? reactionsBorderColor,
Color? reactionsMaskColor,
Color? linkBackgroundColor,
}) =>
MessageThemeData(
messageTextStyle: messageTextStyle ?? this.messageTextStyle,
@@ -81,6 +86,7 @@ class MessageThemeData with Diagnosticable {
reactionsBackgroundColor ?? this.reactionsBackgroundColor,
reactionsBorderColor: reactionsBorderColor ?? this.reactionsBorderColor,
reactionsMaskColor: reactionsMaskColor ?? this.reactionsMaskColor,
linkBackgroundColor: linkBackgroundColor ?? this.linkBackgroundColor,
);
/// Linearly interpolate from one [MessageThemeData] to another.
@@ -109,6 +115,8 @@ class MessageThemeData with Diagnosticable {
reactionsMaskColor:
Color.lerp(a.reactionsMaskColor, b.reactionsMaskColor, t),
repliesStyle: TextStyle.lerp(a.repliesStyle, b.repliesStyle, t),
linkBackgroundColor:
Color.lerp(a.linkBackgroundColor, b.linkBackgroundColor, t),
);
/// Merge with a theme
@@ -131,6 +139,7 @@ class MessageThemeData with Diagnosticable {
reactionsBackgroundColor: other.reactionsBackgroundColor,
reactionsBorderColor: other.reactionsBorderColor,
reactionsMaskColor: other.reactionsMaskColor,
linkBackgroundColor: other.linkBackgroundColor,
);
}
@@ -149,7 +158,8 @@ class MessageThemeData with Diagnosticable {
reactionsBackgroundColor == other.reactionsBackgroundColor &&
reactionsBorderColor == other.reactionsBorderColor &&
reactionsMaskColor == other.reactionsMaskColor &&
avatarTheme == other.avatarTheme;
avatarTheme == other.avatarTheme &&
linkBackgroundColor == other.linkBackgroundColor;
@override
int get hashCode =>
@@ -163,7 +173,8 @@ class MessageThemeData with Diagnosticable {
reactionsBackgroundColor.hashCode ^
reactionsBorderColor.hashCode ^
reactionsMaskColor.hashCode ^
avatarTheme.hashCode;
avatarTheme.hashCode ^
linkBackgroundColor.hashCode;
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
@@ -179,6 +190,7 @@ class MessageThemeData with Diagnosticable {
..add(DiagnosticsProperty('avatarTheme', avatarTheme))
..add(ColorProperty('reactionsBackgroundColor', reactionsBackgroundColor))
..add(ColorProperty('reactionsBorderColor', reactionsBorderColor))
..add(ColorProperty('reactionsMaskColor', reactionsMaskColor));
..add(ColorProperty('reactionsMaskColor', reactionsMaskColor))
..add(ColorProperty('linkBackgroundColor', linkBackgroundColor));
}
}