chore: more upgrades for channel_header_theme.dart

* Renamed:
  * title -> titleStyle
  * subtitle -> subtitleStyle
* Added
  * ==
  * hashcode
  * debugFillProperties
  * lerp
This commit is contained in:
groovinchip
2021-07-27 13:33:58 -04:00
parent 8bf45f8501
commit 3a072fc836
7 changed files with 66 additions and 21 deletions
@@ -169,7 +169,7 @@ class ChannelHeader extends StatelessWidget implements PreferredSizeWidget {
title ??
ChannelName(
textStyle: chatThemeData
.channelTheme.channelHeaderTheme.title,
.channelTheme.channelHeaderTheme.titleStyle,
),
const SizedBox(height: 2),
subtitle ??
@@ -177,7 +177,7 @@ class ChannelHeader extends StatelessWidget implements PreferredSizeWidget {
showTypingIndicator: showTypingIndicator,
channel: channel,
textStyle: chatThemeData
.channelTheme.channelHeaderTheme.subtitle,
.channelTheme.channelHeaderTheme.subtitleStyle,
),
],
),
@@ -64,7 +64,7 @@ class ChannelInfo extends StatelessWidget {
style: StreamChatTheme.of(context)
.channelTheme
.channelHeaderTheme
.subtitle,
.subtitleStyle,
);
} else {
final userId = StreamChat.of(context).currentUser?.id;
@@ -628,7 +628,7 @@ class _MessageListViewState extends State<MessageListView> {
child: Text(
'$replyCount ${replyCount == 1 ? 'Reply' : 'Replies'}',
textAlign: TextAlign.center,
style: _streamTheme.channelTheme.channelHeaderTheme.subtitle,
style: _streamTheme.channelTheme.channelHeaderTheme.subtitleStyle,
),
),
);
@@ -288,8 +288,8 @@ class StreamChatThemeData {
),
),
color: colorTheme.barsBg,
title: textTheme.headlineBold,
subtitle: textTheme.footnote.copyWith(
titleStyle: textTheme.headlineBold,
subtitleStyle: textTheme.footnote.copyWith(
color: const Color(0xff7A7A7A),
),
),
@@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:stream_chat_flutter/src/stream_chat_theme.dart';
import 'package:stream_chat_flutter/src/theme/avatar_theme.dart';
import 'package:stream_chat_flutter/src/theme/themes.dart';
/// Overrides the default style of [ChannelHeader] descendants.
///
@@ -59,17 +60,17 @@ class ChannelHeaderTheme extends InheritedTheme {
class ChannelHeaderThemeData with Diagnosticable {
/// Creates a [ChannelHeaderThemeData]
const ChannelHeaderThemeData({
this.title,
this.subtitle,
this.titleStyle,
this.subtitleStyle,
this.avatarTheme,
this.color,
});
/// Theme for title
final TextStyle? title;
final TextStyle? titleStyle;
/// Theme for subtitle
final TextStyle? subtitle;
final TextStyle? subtitleStyle;
/// Theme for avatar
final AvatarThemeData? avatarTheme;
@@ -79,26 +80,70 @@ class ChannelHeaderThemeData with Diagnosticable {
/// Copy with theme
ChannelHeaderThemeData copyWith({
TextStyle? title,
TextStyle? subtitle,
TextStyle? titleStyle,
TextStyle? subtitleStyle,
AvatarThemeData? avatarTheme,
Color? color,
}) =>
ChannelHeaderThemeData(
title: title ?? this.title,
subtitle: subtitle ?? this.subtitle,
titleStyle: titleStyle ?? this.titleStyle,
subtitleStyle: subtitleStyle ?? this.subtitleStyle,
avatarTheme: avatarTheme ?? this.avatarTheme,
color: color ?? this.color,
);
/// Linearly interpolate between two [ChannelHeaderThemeData].
///
/// All the properties must be non-null.
ChannelHeaderThemeData lerp(
ChannelHeaderThemeData a,
ChannelHeaderThemeData b,
double t,
) =>
ChannelHeaderThemeData(
titleStyle: TextStyle.lerp(a.titleStyle, b.titleStyle, t),
subtitleStyle: TextStyle.lerp(a.subtitleStyle, b.subtitleStyle, t),
avatarTheme:
const AvatarThemeData().lerp(a.avatarTheme!, b.avatarTheme!, t),
color: Color.lerp(a.color, b.color, t),
);
/// Merge with other [ChannelHeaderThemeData]
ChannelHeaderThemeData merge(ChannelHeaderThemeData? other) {
if (other == null) return this;
return copyWith(
title: title?.merge(other.title) ?? other.title,
subtitle: subtitle?.merge(other.subtitle) ?? other.subtitle,
titleStyle: titleStyle?.merge(other.titleStyle) ?? other.titleStyle,
subtitleStyle:
subtitleStyle?.merge(other.subtitleStyle) ?? other.subtitleStyle,
avatarTheme: avatarTheme?.merge(other.avatarTheme) ?? other.avatarTheme,
color: other.color,
);
}
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is ChannelHeaderThemeData &&
runtimeType == other.runtimeType &&
titleStyle == other.titleStyle &&
subtitleStyle == other.subtitleStyle &&
avatarTheme == other.avatarTheme &&
color == other.color;
@override
int get hashCode =>
titleStyle.hashCode ^
subtitleStyle.hashCode ^
avatarTheme.hashCode ^
color.hashCode;
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty('title', titleStyle))
..add(DiagnosticsProperty('subtitle', subtitleStyle))
..add(DiagnosticsProperty('avatarTheme', avatarTheme))
..add(ColorProperty('color', color));
}
}
@@ -86,7 +86,7 @@ class GalleryHeaderThemeData with Diagnosticable {
/// The [TextStyle] to use for the [GalleryHeader] subtitle text.
///
/// Defaults to [ChannelPreviewTheme.subtitle].
/// Defaults to [ChannelPreviewTheme.subtitleStyle].
final TextStyle? subtitleTextStyle;
///
@@ -112,12 +112,12 @@ class ThreadHeader extends StatelessWidget implements PreferredSizeWidget {
children: [
Text(
'with ',
style: chatThemeData.channelTheme.channelHeaderTheme.subtitle,
style: chatThemeData.channelTheme.channelHeaderTheme.subtitleStyle,
),
Flexible(
child: ChannelName(
textStyle:
chatThemeData.channelTheme.channelHeaderTheme.subtitle,
chatThemeData.channelTheme.channelHeaderTheme.subtitleStyle,
),
),
],
@@ -150,14 +150,14 @@ class ThreadHeader extends StatelessWidget implements PreferredSizeWidget {
title ??
Text(
'Thread Reply',
style: chatThemeData.channelTheme.channelHeaderTheme.title,
style: chatThemeData.channelTheme.channelHeaderTheme.titleStyle,
),
const SizedBox(height: 2),
if (showTypingIndicator)
TypingIndicator(
alignment: Alignment.center,
channel: StreamChannel.of(context).channel,
style: chatThemeData.channelTheme.channelHeaderTheme.subtitle,
style: chatThemeData.channelTheme.channelHeaderTheme.subtitleStyle,
parentId: parent.id,
alternativeWidget: defaultSubtitle,
)