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 ?? title ??
ChannelName( ChannelName(
textStyle: chatThemeData textStyle: chatThemeData
.channelTheme.channelHeaderTheme.title, .channelTheme.channelHeaderTheme.titleStyle,
), ),
const SizedBox(height: 2), const SizedBox(height: 2),
subtitle ?? subtitle ??
@@ -177,7 +177,7 @@ class ChannelHeader extends StatelessWidget implements PreferredSizeWidget {
showTypingIndicator: showTypingIndicator, showTypingIndicator: showTypingIndicator,
channel: channel, channel: channel,
textStyle: chatThemeData textStyle: chatThemeData
.channelTheme.channelHeaderTheme.subtitle, .channelTheme.channelHeaderTheme.subtitleStyle,
), ),
], ],
), ),
@@ -64,7 +64,7 @@ class ChannelInfo extends StatelessWidget {
style: StreamChatTheme.of(context) style: StreamChatTheme.of(context)
.channelTheme .channelTheme
.channelHeaderTheme .channelHeaderTheme
.subtitle, .subtitleStyle,
); );
} else { } else {
final userId = StreamChat.of(context).currentUser?.id; final userId = StreamChat.of(context).currentUser?.id;
@@ -628,7 +628,7 @@ class _MessageListViewState extends State<MessageListView> {
child: Text( child: Text(
'$replyCount ${replyCount == 1 ? 'Reply' : 'Replies'}', '$replyCount ${replyCount == 1 ? 'Reply' : 'Replies'}',
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: _streamTheme.channelTheme.channelHeaderTheme.subtitle, style: _streamTheme.channelTheme.channelHeaderTheme.subtitleStyle,
), ),
), ),
); );
@@ -288,8 +288,8 @@ class StreamChatThemeData {
), ),
), ),
color: colorTheme.barsBg, color: colorTheme.barsBg,
title: textTheme.headlineBold, titleStyle: textTheme.headlineBold,
subtitle: textTheme.footnote.copyWith( subtitleStyle: textTheme.footnote.copyWith(
color: const Color(0xff7A7A7A), color: const Color(0xff7A7A7A),
), ),
), ),
@@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:stream_chat_flutter/src/stream_chat_theme.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/avatar_theme.dart';
import 'package:stream_chat_flutter/src/theme/themes.dart';
/// Overrides the default style of [ChannelHeader] descendants. /// Overrides the default style of [ChannelHeader] descendants.
/// ///
@@ -59,17 +60,17 @@ class ChannelHeaderTheme extends InheritedTheme {
class ChannelHeaderThemeData with Diagnosticable { class ChannelHeaderThemeData with Diagnosticable {
/// Creates a [ChannelHeaderThemeData] /// Creates a [ChannelHeaderThemeData]
const ChannelHeaderThemeData({ const ChannelHeaderThemeData({
this.title, this.titleStyle,
this.subtitle, this.subtitleStyle,
this.avatarTheme, this.avatarTheme,
this.color, this.color,
}); });
/// Theme for title /// Theme for title
final TextStyle? title; final TextStyle? titleStyle;
/// Theme for subtitle /// Theme for subtitle
final TextStyle? subtitle; final TextStyle? subtitleStyle;
/// Theme for avatar /// Theme for avatar
final AvatarThemeData? avatarTheme; final AvatarThemeData? avatarTheme;
@@ -79,26 +80,70 @@ class ChannelHeaderThemeData with Diagnosticable {
/// Copy with theme /// Copy with theme
ChannelHeaderThemeData copyWith({ ChannelHeaderThemeData copyWith({
TextStyle? title, TextStyle? titleStyle,
TextStyle? subtitle, TextStyle? subtitleStyle,
AvatarThemeData? avatarTheme, AvatarThemeData? avatarTheme,
Color? color, Color? color,
}) => }) =>
ChannelHeaderThemeData( ChannelHeaderThemeData(
title: title ?? this.title, titleStyle: titleStyle ?? this.titleStyle,
subtitle: subtitle ?? this.subtitle, subtitleStyle: subtitleStyle ?? this.subtitleStyle,
avatarTheme: avatarTheme ?? this.avatarTheme, avatarTheme: avatarTheme ?? this.avatarTheme,
color: color ?? this.color, 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] /// Merge with other [ChannelHeaderThemeData]
ChannelHeaderThemeData merge(ChannelHeaderThemeData? other) { ChannelHeaderThemeData merge(ChannelHeaderThemeData? other) {
if (other == null) return this; if (other == null) return this;
return copyWith( return copyWith(
title: title?.merge(other.title) ?? other.title, titleStyle: titleStyle?.merge(other.titleStyle) ?? other.titleStyle,
subtitle: subtitle?.merge(other.subtitle) ?? other.subtitle, subtitleStyle:
subtitleStyle?.merge(other.subtitleStyle) ?? other.subtitleStyle,
avatarTheme: avatarTheme?.merge(other.avatarTheme) ?? other.avatarTheme, avatarTheme: avatarTheme?.merge(other.avatarTheme) ?? other.avatarTheme,
color: other.color, 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. /// The [TextStyle] to use for the [GalleryHeader] subtitle text.
/// ///
/// Defaults to [ChannelPreviewTheme.subtitle]. /// Defaults to [ChannelPreviewTheme.subtitleStyle].
final TextStyle? subtitleTextStyle; final TextStyle? subtitleTextStyle;
/// ///
@@ -112,12 +112,12 @@ class ThreadHeader extends StatelessWidget implements PreferredSizeWidget {
children: [ children: [
Text( Text(
'with ', 'with ',
style: chatThemeData.channelTheme.channelHeaderTheme.subtitle, style: chatThemeData.channelTheme.channelHeaderTheme.subtitleStyle,
), ),
Flexible( Flexible(
child: ChannelName( child: ChannelName(
textStyle: textStyle:
chatThemeData.channelTheme.channelHeaderTheme.subtitle, chatThemeData.channelTheme.channelHeaderTheme.subtitleStyle,
), ),
), ),
], ],
@@ -150,14 +150,14 @@ class ThreadHeader extends StatelessWidget implements PreferredSizeWidget {
title ?? title ??
Text( Text(
'Thread Reply', 'Thread Reply',
style: chatThemeData.channelTheme.channelHeaderTheme.title, style: chatThemeData.channelTheme.channelHeaderTheme.titleStyle,
), ),
const SizedBox(height: 2), const SizedBox(height: 2),
if (showTypingIndicator) if (showTypingIndicator)
TypingIndicator( TypingIndicator(
alignment: Alignment.center, alignment: Alignment.center,
channel: StreamChannel.of(context).channel, channel: StreamChannel.of(context).channel,
style: chatThemeData.channelTheme.channelHeaderTheme.subtitle, style: chatThemeData.channelTheme.channelHeaderTheme.subtitleStyle,
parentId: parent.id, parentId: parent.id,
alternativeWidget: defaultSubtitle, alternativeWidget: defaultSubtitle,
) )