chore: upgrade ChannelHeaderTheme

This commit is contained in:
groovinchip
2021-07-27 13:12:51 -04:00
parent 66ea5557e8
commit 1fa8c5264a
3 changed files with 69 additions and 15 deletions
@@ -188,10 +188,10 @@ class StreamChatThemeData {
/// Theme configuration for the [UserListView] widget.
final UserListViewThemeData userListViewTheme;
/// Theme configuration for the [] widget.
/// Theme configuration for the [MessageSearchListView] widget.
final MessageSearchListViewThemeData messageSearchListViewTheme;
/// Theme configuration for the [] widget.
/// Theme configuration for the [UserAvatar] widget.
final AvatarThemeData avatarTheme;
/// Creates a copy of [StreamChatThemeData] with specified attributes
@@ -279,7 +279,7 @@ class StreamChatThemeData {
final iconTheme =
IconThemeData(color: colorTheme.textHighEmphasis.withOpacity(.5));
final channelTheme = ChannelTheme(
channelHeaderTheme: ChannelHeaderTheme(
channelHeaderTheme: ChannelHeaderThemeData(
avatarTheme: AvatarThemeData(
borderRadius: BorderRadius.circular(20),
constraints: const BoxConstraints.tightFor(
@@ -497,7 +497,7 @@ class StreamChatThemeData {
backgroundColor: colorTheme.appBg,
),
avatarTheme: AvatarThemeData(
borderRadius: BorderRadius.circular(8),
borderRadius: BorderRadius.circular(20),
),
);
}
@@ -1,10 +1,64 @@
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';
/// Theme for [ChannelHeader]
class ChannelHeaderTheme {
/// Constructor for creating a [ChannelHeaderTheme]
/// Overrides the default style of [ChannelHeader] descendants.
///
/// See also:
///
/// * [ChannelHeaderThemeData], which is used to configure this theme.
class ChannelHeaderTheme extends InheritedTheme {
/// Creates a [ChannelHeaderTheme].
///
/// The [data] parameter must not be null.
const ChannelHeaderTheme({
Key? key,
required this.data,
required Widget child,
}) : super(key: key, child: child);
/// The configuration of this theme.
final ChannelHeaderThemeData data;
/// The closest instance of this class that encloses the given context.
///
/// If there is no enclosing [ChannelHeaderTheme] widget, then
/// [StreamChatThemeData.channelTheme.channelHeaderTheme] is used.
///
/// Typical usage is as follows:
///
/// ```dart
/// final theme = ChannelHeaderTheme.of(context);
/// ```
static ChannelHeaderThemeData of(BuildContext context) {
final channelHeaderTheme =
context.dependOnInheritedWidgetOfExactType<ChannelHeaderTheme>();
return channelHeaderTheme?.data ??
StreamChatTheme.of(context).channelTheme.channelHeaderTheme;
}
@override
Widget wrap(BuildContext context, Widget child) =>
ChannelHeaderTheme(data: data, child: child);
@override
bool updateShouldNotify(ChannelHeaderTheme oldWidget) =>
data != oldWidget.data;
}
/// A style that overrides the default appearance of [ChannelHeader]s when used
/// with [ChannelHeaderTheme] or with the overall [StreamChatTheme]'s
/// [StreamChatThemeData.channelHeaderTheme].
///
/// See also:
///
/// * [ChannelHeaderTheme], the theme which is configured with this class.
/// * [StreamChatThemeData.channelHeaderTheme], which can be used to override
/// the default style for [ChannelHeader]s below the overall [StreamChatTheme].
class ChannelHeaderThemeData with Diagnosticable {
/// Creates a [ChannelHeaderThemeData]
const ChannelHeaderThemeData({
this.title,
this.subtitle,
this.avatarTheme,
@@ -20,25 +74,25 @@ class ChannelHeaderTheme {
/// Theme for avatar
final AvatarThemeData? avatarTheme;
/// Color for [ChannelHeaderTheme]
/// Color for [ChannelHeaderThemeData]
final Color? color;
/// Copy with theme
ChannelHeaderTheme copyWith({
ChannelHeaderThemeData copyWith({
TextStyle? title,
TextStyle? subtitle,
AvatarThemeData? avatarTheme,
Color? color,
}) =>
ChannelHeaderTheme(
ChannelHeaderThemeData(
title: title ?? this.title,
subtitle: subtitle ?? this.subtitle,
avatarTheme: avatarTheme ?? this.avatarTheme,
color: color ?? this.color,
);
/// Merge with other [ChannelHeaderTheme]
ChannelHeaderTheme merge(ChannelHeaderTheme? other) {
/// Merge with other [ChannelHeaderThemeData]
ChannelHeaderThemeData merge(ChannelHeaderThemeData? other) {
if (other == null) return this;
return copyWith(
title: title?.merge(other.title) ?? other.title,
@@ -47,4 +101,4 @@ class ChannelHeaderTheme {
color: other.color,
);
}
}
}
@@ -8,11 +8,11 @@ class ChannelTheme {
});
/// Theme of the [ChannelHeader] widget
final ChannelHeaderTheme channelHeaderTheme;
final ChannelHeaderThemeData channelHeaderTheme;
/// Creates a copy of [ChannelTheme] with specified attributes overridden.
ChannelTheme copyWith({
ChannelHeaderTheme? channelHeaderTheme,
ChannelHeaderThemeData? channelHeaderTheme,
}) =>
ChannelTheme(
channelHeaderTheme: channelHeaderTheme ?? this.channelHeaderTheme,