chore: update ChannelListHeaderTheme
This commit is contained in:
@@ -45,7 +45,7 @@ typedef TitleBuilder = Widget Function(
|
|||||||
/// if you don't have it in the widget tree.
|
/// if you don't have it in the widget tree.
|
||||||
///
|
///
|
||||||
/// The widget components render the ui based on the first ancestor of type
|
/// The widget components render the ui based on the first ancestor of type
|
||||||
/// [StreamChatTheme] and on its [ChannelListHeaderTheme] property.
|
/// [StreamChatTheme] and on its [ChannelListHeaderThemeData] property.
|
||||||
/// Modify it to change the widget appearance.
|
/// Modify it to change the widget appearance.
|
||||||
class ChannelListHeader extends StatelessWidget implements PreferredSizeWidget {
|
class ChannelListHeader extends StatelessWidget implements PreferredSizeWidget {
|
||||||
/// Instantiates a ChannelListHeader
|
/// Instantiates a ChannelListHeader
|
||||||
@@ -115,6 +115,7 @@ class ChannelListHeader extends StatelessWidget implements PreferredSizeWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final chatThemeData = StreamChatTheme.of(context);
|
final chatThemeData = StreamChatTheme.of(context);
|
||||||
|
final channelListHeaderThemeData = ChannelListHeaderTheme.of(context);
|
||||||
return InfoTile(
|
return InfoTile(
|
||||||
// ignore: avoid_bool_literals_in_conditional_expressions
|
// ignore: avoid_bool_literals_in_conditional_expressions
|
||||||
showMessage: showConnectionStateTile ? showStatus : false,
|
showMessage: showConnectionStateTile ? showStatus : false,
|
||||||
@@ -123,7 +124,7 @@ class ChannelListHeader extends StatelessWidget implements PreferredSizeWidget {
|
|||||||
textTheme: Theme.of(context).textTheme,
|
textTheme: Theme.of(context).textTheme,
|
||||||
brightness: Theme.of(context).brightness,
|
brightness: Theme.of(context).brightness,
|
||||||
elevation: 1,
|
elevation: 1,
|
||||||
backgroundColor: chatThemeData.channelListHeaderTheme.color,
|
backgroundColor: channelListHeaderThemeData.color,
|
||||||
centerTitle: true,
|
centerTitle: true,
|
||||||
leading: leading ??
|
leading: leading ??
|
||||||
Center(
|
Center(
|
||||||
@@ -138,10 +139,10 @@ class ChannelListHeader extends StatelessWidget implements PreferredSizeWidget {
|
|||||||
}
|
}
|
||||||
Scaffold.of(context).openDrawer();
|
Scaffold.of(context).openDrawer();
|
||||||
},
|
},
|
||||||
borderRadius: chatThemeData
|
borderRadius: channelListHeaderThemeData
|
||||||
.channelListHeaderTheme.avatarTheme?.borderRadius,
|
.avatarTheme?.borderRadius,
|
||||||
constraints: chatThemeData
|
constraints: channelListHeaderThemeData
|
||||||
.channelListHeaderTheme.avatarTheme?.constraints,
|
.avatarTheme?.constraints,
|
||||||
)
|
)
|
||||||
: const Offstage(),
|
: const Offstage(),
|
||||||
),
|
),
|
||||||
@@ -227,10 +228,7 @@ class ChannelListHeader extends StatelessWidget implements PreferredSizeWidget {
|
|||||||
const SizedBox(width: 10),
|
const SizedBox(width: 10),
|
||||||
Text(
|
Text(
|
||||||
'Searching for Network',
|
'Searching for Network',
|
||||||
style: StreamChatTheme.of(context)
|
style: ChannelListHeaderTheme.of(context).titleStyle?.copyWith(
|
||||||
.channelListHeaderTheme
|
|
||||||
.title
|
|
||||||
?.copyWith(
|
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
@@ -248,7 +246,7 @@ class ChannelListHeader extends StatelessWidget implements PreferredSizeWidget {
|
|||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
'Offline...',
|
'Offline...',
|
||||||
style: chatThemeData.channelListHeaderTheme.title?.copyWith(
|
style: chatThemeData.channelListHeaderTheme.titleStyle?.copyWith(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
@@ -259,7 +257,7 @@ class ChannelListHeader extends StatelessWidget implements PreferredSizeWidget {
|
|||||||
..openConnection(),
|
..openConnection(),
|
||||||
child: Text(
|
child: Text(
|
||||||
'Try Again',
|
'Try Again',
|
||||||
style: chatThemeData.channelListHeaderTheme.title?.copyWith(
|
style: chatThemeData.channelListHeaderTheme.titleStyle?.copyWith(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
color: chatThemeData.colorTheme.accentPrimary,
|
color: chatThemeData.colorTheme.accentPrimary,
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class StreamChatThemeData {
|
|||||||
Brightness? brightness,
|
Brightness? brightness,
|
||||||
TextTheme? textTheme,
|
TextTheme? textTheme,
|
||||||
ColorTheme? colorTheme,
|
ColorTheme? colorTheme,
|
||||||
ChannelListHeaderTheme? channelListHeaderTheme,
|
ChannelListHeaderThemeData? channelListHeaderTheme,
|
||||||
ChannelPreviewThemeData? channelPreviewTheme,
|
ChannelPreviewThemeData? channelPreviewTheme,
|
||||||
ChannelHeaderThemeData? channelHeaderTheme,
|
ChannelHeaderThemeData? channelHeaderTheme,
|
||||||
MessageThemeData? otherMessageTheme,
|
MessageThemeData? otherMessageTheme,
|
||||||
@@ -145,7 +145,7 @@ class StreamChatThemeData {
|
|||||||
final ChannelPreviewThemeData channelPreviewTheme;
|
final ChannelPreviewThemeData channelPreviewTheme;
|
||||||
|
|
||||||
/// Theme of the [ChannelListHeader]
|
/// Theme of the [ChannelListHeader]
|
||||||
final ChannelListHeaderTheme channelListHeaderTheme;
|
final ChannelListHeaderThemeData channelListHeaderTheme;
|
||||||
|
|
||||||
/// Theme of the chat widgets dedicated to a channel header
|
/// Theme of the chat widgets dedicated to a channel header
|
||||||
final ChannelHeaderThemeData channelHeaderTheme;
|
final ChannelHeaderThemeData channelHeaderTheme;
|
||||||
@@ -200,7 +200,7 @@ class StreamChatThemeData {
|
|||||||
MessageInputThemeData? messageInputTheme,
|
MessageInputThemeData? messageInputTheme,
|
||||||
Widget Function(BuildContext, User)? defaultUserImage,
|
Widget Function(BuildContext, User)? defaultUserImage,
|
||||||
IconThemeData? primaryIconTheme,
|
IconThemeData? primaryIconTheme,
|
||||||
ChannelListHeaderTheme? channelListHeaderTheme,
|
ChannelListHeaderThemeData? channelListHeaderTheme,
|
||||||
List<ReactionIcon>? reactionIcons,
|
List<ReactionIcon>? reactionIcons,
|
||||||
GalleryHeaderThemeData? galleryHeaderTheme,
|
GalleryHeaderThemeData? galleryHeaderTheme,
|
||||||
GalleryFooterThemeData? galleryFooterTheme,
|
GalleryFooterThemeData? galleryFooterTheme,
|
||||||
@@ -312,7 +312,7 @@ class StreamChatThemeData {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
channelPreviewTheme: channelPreviewTheme,
|
channelPreviewTheme: channelPreviewTheme,
|
||||||
channelListHeaderTheme: ChannelListHeaderTheme(
|
channelListHeaderTheme: ChannelListHeaderThemeData(
|
||||||
avatarTheme: AvatarThemeData(
|
avatarTheme: AvatarThemeData(
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
constraints: const BoxConstraints.tightFor(
|
constraints: const BoxConstraints.tightFor(
|
||||||
@@ -321,7 +321,7 @@ class StreamChatThemeData {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
color: colorTheme.barsBg,
|
color: colorTheme.barsBg,
|
||||||
title: textTheme.headlineBold,
|
titleStyle: textTheme.headlineBold,
|
||||||
),
|
),
|
||||||
channelHeaderTheme: channelHeaderTheme,
|
channelHeaderTheme: channelHeaderTheme,
|
||||||
ownMessageTheme: MessageThemeData(
|
ownMessageTheme: MessageThemeData(
|
||||||
|
|||||||
@@ -1,17 +1,63 @@
|
|||||||
|
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/theme/avatar_theme.dart';
|
import 'package:stream_chat_flutter/src/theme/avatar_theme.dart';
|
||||||
|
|
||||||
/// Theme dedicated to the [ChannelListHeader]
|
/// Overrides the default style of [ChannelListHeader] descendants.
|
||||||
class ChannelListHeaderTheme {
|
///
|
||||||
/// Returns a new [ChannelListHeaderTheme]
|
/// See also:
|
||||||
|
///
|
||||||
|
/// * [ChannelListHeaderThemeData], which is used to configure this theme.
|
||||||
|
class ChannelListHeaderTheme extends InheritedTheme {
|
||||||
|
/// Creates a [ChannelListHeaderTheme].
|
||||||
|
///
|
||||||
|
/// The [data] parameter must not be null.
|
||||||
const ChannelListHeaderTheme({
|
const ChannelListHeaderTheme({
|
||||||
this.title,
|
Key? key,
|
||||||
|
required this.data,
|
||||||
|
required Widget child,
|
||||||
|
}) : super(key: key, child: child);
|
||||||
|
|
||||||
|
/// The configuration of this theme.
|
||||||
|
final ChannelListHeaderThemeData data;
|
||||||
|
|
||||||
|
/// The closest instance of this class that encloses the given context.
|
||||||
|
///
|
||||||
|
/// If there is no enclosing [ChannelListHeaderTheme] widget, then
|
||||||
|
/// [StreamChatThemeData.channelListHeaderTheme] is used.
|
||||||
|
///
|
||||||
|
/// Typical usage is as follows:
|
||||||
|
///
|
||||||
|
/// ```dart
|
||||||
|
/// final theme = ChannelListHeaderTheme.of(context);
|
||||||
|
/// ```
|
||||||
|
static ChannelListHeaderThemeData of(BuildContext context) {
|
||||||
|
final channelListHeaderTheme =
|
||||||
|
context.dependOnInheritedWidgetOfExactType<ChannelListHeaderTheme>();
|
||||||
|
return channelListHeaderTheme?.data ??
|
||||||
|
StreamChatTheme.of(context).channelListHeaderTheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget wrap(BuildContext context, Widget child) =>
|
||||||
|
ChannelListHeaderTheme(data: data, child: child);
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool updateShouldNotify(ChannelListHeaderTheme oldWidget) =>
|
||||||
|
data != oldWidget.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Theme dedicated to the [ChannelListHeader]
|
||||||
|
class ChannelListHeaderThemeData with Diagnosticable {
|
||||||
|
/// Returns a new [ChannelListHeaderThemeData]
|
||||||
|
const ChannelListHeaderThemeData({
|
||||||
|
this.titleStyle,
|
||||||
this.avatarTheme,
|
this.avatarTheme,
|
||||||
this.color,
|
this.color,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Style of the title text
|
/// Style of the title text
|
||||||
final TextStyle? title;
|
final TextStyle? titleStyle;
|
||||||
|
|
||||||
/// Theme dedicated to the userAvatar
|
/// Theme dedicated to the userAvatar
|
||||||
final AvatarThemeData? avatarTheme;
|
final AvatarThemeData? avatarTheme;
|
||||||
@@ -19,25 +65,61 @@ class ChannelListHeaderTheme {
|
|||||||
/// Background color of the appbar
|
/// Background color of the appbar
|
||||||
final Color? color;
|
final Color? color;
|
||||||
|
|
||||||
/// Returns a new [ChannelListHeaderTheme] replacing some of its properties
|
/// Returns a new [ChannelListHeaderThemeData] replacing some of its
|
||||||
ChannelListHeaderTheme copyWith({
|
/// properties
|
||||||
TextStyle? title,
|
ChannelListHeaderThemeData copyWith({
|
||||||
|
TextStyle? titleStyle,
|
||||||
AvatarThemeData? avatarTheme,
|
AvatarThemeData? avatarTheme,
|
||||||
Color? color,
|
Color? color,
|
||||||
}) =>
|
}) =>
|
||||||
ChannelListHeaderTheme(
|
ChannelListHeaderThemeData(
|
||||||
title: title ?? this.title,
|
titleStyle: titleStyle ?? this.titleStyle,
|
||||||
avatarTheme: avatarTheme ?? this.avatarTheme,
|
avatarTheme: avatarTheme ?? this.avatarTheme,
|
||||||
color: color ?? this.color,
|
color: color ?? this.color,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Merges [this] [ChannelListHeaderTheme] with the [other]
|
/// Linearly interpolate from one [ChannelListHeaderThemeData] to another.
|
||||||
ChannelListHeaderTheme merge(ChannelListHeaderTheme? other) {
|
ChannelListHeaderThemeData lerp(
|
||||||
|
ChannelListHeaderThemeData a,
|
||||||
|
ChannelListHeaderThemeData b,
|
||||||
|
double t,
|
||||||
|
) =>
|
||||||
|
ChannelListHeaderThemeData(
|
||||||
|
avatarTheme:
|
||||||
|
const AvatarThemeData().lerp(a.avatarTheme!, b.avatarTheme!, t),
|
||||||
|
color: Color.lerp(a.color, b.color, t),
|
||||||
|
titleStyle: TextStyle.lerp(a.titleStyle, b.titleStyle, t),
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Merges [this] [ChannelListHeaderThemeData] with the [other]
|
||||||
|
ChannelListHeaderThemeData merge(ChannelListHeaderThemeData? 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,
|
||||||
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 ChannelListHeaderThemeData &&
|
||||||
|
runtimeType == other.runtimeType &&
|
||||||
|
titleStyle == other.titleStyle &&
|
||||||
|
avatarTheme == other.avatarTheme &&
|
||||||
|
color == other.color;
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode =>
|
||||||
|
titleStyle.hashCode ^ avatarTheme.hashCode ^ color.hashCode;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
||||||
|
super.debugFillProperties(properties);
|
||||||
|
properties
|
||||||
|
..add(DiagnosticsProperty('titleStyle', titleStyle))
|
||||||
|
..add(DiagnosticsProperty('avatarTheme', avatarTheme))
|
||||||
|
..add(ColorProperty('color', color));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user