From 1fa8c5264ab18d00e42d213deab85a6078bdef84 Mon Sep 17 00:00:00 2001 From: groovinchip Date: Tue, 27 Jul 2021 11:46:19 -0400 Subject: [PATCH] chore: upgrade ChannelHeaderTheme --- .../lib/src/stream_chat_theme.dart | 8 +-- .../lib/src/theme/channel_header_theme.dart | 72 ++++++++++++++++--- .../lib/src/theme/channel_theme.dart | 4 +- 3 files changed, 69 insertions(+), 15 deletions(-) diff --git a/packages/stream_chat_flutter/lib/src/stream_chat_theme.dart b/packages/stream_chat_flutter/lib/src/stream_chat_theme.dart index d2eb0df0..38511e38 100644 --- a/packages/stream_chat_flutter/lib/src/stream_chat_theme.dart +++ b/packages/stream_chat_flutter/lib/src/stream_chat_theme.dart @@ -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), ), ); } diff --git a/packages/stream_chat_flutter/lib/src/theme/channel_header_theme.dart b/packages/stream_chat_flutter/lib/src/theme/channel_header_theme.dart index be1d0347..8ea92615 100644 --- a/packages/stream_chat_flutter/lib/src/theme/channel_header_theme.dart +++ b/packages/stream_chat_flutter/lib/src/theme/channel_header_theme.dart @@ -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(); + 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, ); } -} \ No newline at end of file +} diff --git a/packages/stream_chat_flutter/lib/src/theme/channel_theme.dart b/packages/stream_chat_flutter/lib/src/theme/channel_theme.dart index bf752f94..a8c6260d 100644 --- a/packages/stream_chat_flutter/lib/src/theme/channel_theme.dart +++ b/packages/stream_chat_flutter/lib/src/theme/channel_theme.dart @@ -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,