chore: set MessageSeachListView bg color via theme and stop setting scaffold bg color
New classes: * MessageSearchListViewTheme * MessageSearchListViewThemeData
This commit is contained in:
@@ -144,58 +144,61 @@ class _MessageSearchListViewState extends State<MessageSearchListView> {
|
|||||||
widget.messageSearchListController ?? _defaultController;
|
widget.messageSearchListController ?? _defaultController;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => MessageSearchListCore(
|
Widget build(BuildContext context) => ColoredBox(
|
||||||
filters: widget.filters,
|
color: MessageSearchListViewTheme.of(context).backgroundColor!,
|
||||||
sortOptions: widget.sortOptions,
|
child: MessageSearchListCore(
|
||||||
messageQuery: widget.messageQuery,
|
filters: widget.filters,
|
||||||
paginationParams: widget.paginationParams,
|
sortOptions: widget.sortOptions,
|
||||||
messageFilters: widget.messageFilters,
|
messageQuery: widget.messageQuery,
|
||||||
messageSearchListController: _messageSearchListController,
|
paginationParams: widget.paginationParams,
|
||||||
emptyBuilder: widget.emptyBuilder ??
|
messageFilters: widget.messageFilters,
|
||||||
(context) => LayoutBuilder(
|
messageSearchListController: _messageSearchListController,
|
||||||
builder: (context, viewportConstraints) =>
|
emptyBuilder: widget.emptyBuilder ??
|
||||||
SingleChildScrollView(
|
(context) => LayoutBuilder(
|
||||||
physics: const AlwaysScrollableScrollPhysics(),
|
builder: (context, viewportConstraints) =>
|
||||||
child: ConstrainedBox(
|
SingleChildScrollView(
|
||||||
constraints: BoxConstraints(
|
physics: const AlwaysScrollableScrollPhysics(),
|
||||||
minHeight: viewportConstraints.maxHeight,
|
child: ConstrainedBox(
|
||||||
),
|
constraints: BoxConstraints(
|
||||||
child: const Center(
|
minHeight: viewportConstraints.maxHeight,
|
||||||
child: Text('There are no messages currently'),
|
),
|
||||||
|
child: const Center(
|
||||||
|
child: Text('There are no messages currently'),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
errorBuilder: widget.errorBuilder ??
|
||||||
errorBuilder: widget.errorBuilder ??
|
(BuildContext context, dynamic error) {
|
||||||
(BuildContext context, dynamic error) {
|
if (error is Error) {
|
||||||
if (error is Error) {
|
print(error.stackTrace);
|
||||||
print(error.stackTrace);
|
}
|
||||||
}
|
return InfoTile(
|
||||||
return InfoTile(
|
showMessage: widget.showErrorTile,
|
||||||
showMessage: widget.showErrorTile,
|
tileAnchor: Alignment.topCenter,
|
||||||
tileAnchor: Alignment.topCenter,
|
childAnchor: Alignment.topCenter,
|
||||||
childAnchor: Alignment.topCenter,
|
message: 'An error occurred.',
|
||||||
message: 'An error occurred.',
|
child: Container(),
|
||||||
child: Container(),
|
);
|
||||||
);
|
},
|
||||||
},
|
loadingBuilder: widget.loadingBuilder ??
|
||||||
loadingBuilder: widget.loadingBuilder ??
|
(context) => LayoutBuilder(
|
||||||
(context) => LayoutBuilder(
|
builder: (context, viewportConstraints) =>
|
||||||
builder: (context, viewportConstraints) =>
|
SingleChildScrollView(
|
||||||
SingleChildScrollView(
|
physics: const AlwaysScrollableScrollPhysics(),
|
||||||
physics: const AlwaysScrollableScrollPhysics(),
|
child: ConstrainedBox(
|
||||||
child: ConstrainedBox(
|
constraints: BoxConstraints(
|
||||||
constraints: BoxConstraints(
|
minHeight: viewportConstraints.maxHeight,
|
||||||
minHeight: viewportConstraints.maxHeight,
|
),
|
||||||
),
|
child: const Center(
|
||||||
child: const Center(
|
child: CircularProgressIndicator(),
|
||||||
child: CircularProgressIndicator(),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
childBuilder: widget.childBuilder ?? _buildListView,
|
||||||
childBuilder: widget.childBuilder ?? _buildListView,
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
Widget _separatorBuilder(BuildContext context, int index) => Container(
|
Widget _separatorBuilder(BuildContext context, int index) => Container(
|
||||||
height: 1,
|
height: 1,
|
||||||
|
|||||||
@@ -102,7 +102,6 @@ class StreamChatState extends State<StreamChat> {
|
|||||||
data: materialTheme.copyWith(
|
data: materialTheme.copyWith(
|
||||||
primaryIconTheme: streamTheme.primaryIconTheme,
|
primaryIconTheme: streamTheme.primaryIconTheme,
|
||||||
accentColor: streamTheme.colorTheme.accentPrimary,
|
accentColor: streamTheme.colorTheme.accentPrimary,
|
||||||
scaffoldBackgroundColor: streamTheme.colorTheme.barsBg,
|
|
||||||
),
|
),
|
||||||
child: StreamChatCore(
|
child: StreamChatCore(
|
||||||
client: client,
|
client: client,
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ class StreamChatThemeData {
|
|||||||
MessageListViewThemeData? messageListViewTheme,
|
MessageListViewThemeData? messageListViewTheme,
|
||||||
ChannelListViewThemeData? channelListViewTheme,
|
ChannelListViewThemeData? channelListViewTheme,
|
||||||
UserListViewThemeData? userListViewTheme,
|
UserListViewThemeData? userListViewTheme,
|
||||||
|
MessageSearchListViewThemeData? messageSearchListViewTheme,
|
||||||
}) {
|
}) {
|
||||||
brightness ??= colorTheme?.brightness ?? Brightness.light;
|
brightness ??= colorTheme?.brightness ?? Brightness.light;
|
||||||
final isDark = brightness == Brightness.dark;
|
final isDark = brightness == Brightness.dark;
|
||||||
@@ -89,6 +90,7 @@ class StreamChatThemeData {
|
|||||||
messageListViewTheme: messageListViewTheme,
|
messageListViewTheme: messageListViewTheme,
|
||||||
channelListViewTheme: channelListViewTheme,
|
channelListViewTheme: channelListViewTheme,
|
||||||
userListViewTheme: userListViewTheme,
|
userListViewTheme: userListViewTheme,
|
||||||
|
messageSearchListViewTheme: messageSearchListViewTheme,
|
||||||
);
|
);
|
||||||
|
|
||||||
return defaultData.merge(customizedData);
|
return defaultData.merge(customizedData);
|
||||||
@@ -120,6 +122,7 @@ class StreamChatThemeData {
|
|||||||
required this.messageListViewTheme,
|
required this.messageListViewTheme,
|
||||||
required this.channelListViewTheme,
|
required this.channelListViewTheme,
|
||||||
required this.userListViewTheme,
|
required this.userListViewTheme,
|
||||||
|
required this.messageSearchListViewTheme,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Create a theme from a Material [Theme]
|
/// Create a theme from a Material [Theme]
|
||||||
@@ -184,6 +187,9 @@ class StreamChatThemeData {
|
|||||||
/// Theme configuration for the [UserListView] widget.
|
/// Theme configuration for the [UserListView] widget.
|
||||||
final UserListViewThemeData userListViewTheme;
|
final UserListViewThemeData userListViewTheme;
|
||||||
|
|
||||||
|
/// Theme configuration for the [] widget.
|
||||||
|
final MessageSearchListViewThemeData messageSearchListViewTheme;
|
||||||
|
|
||||||
/// Creates a copy of [StreamChatThemeData] with specified attributes
|
/// Creates a copy of [StreamChatThemeData] with specified attributes
|
||||||
/// overridden.
|
/// overridden.
|
||||||
StreamChatThemeData copyWith({
|
StreamChatThemeData copyWith({
|
||||||
@@ -203,6 +209,7 @@ class StreamChatThemeData {
|
|||||||
MessageListViewThemeData? messageListViewTheme,
|
MessageListViewThemeData? messageListViewTheme,
|
||||||
ChannelListViewThemeData? channelListViewTheme,
|
ChannelListViewThemeData? channelListViewTheme,
|
||||||
UserListViewThemeData? userListViewTheme,
|
UserListViewThemeData? userListViewTheme,
|
||||||
|
MessageSearchListViewThemeData? messageSearchListViewTheme,
|
||||||
}) =>
|
}) =>
|
||||||
StreamChatThemeData.raw(
|
StreamChatThemeData.raw(
|
||||||
channelListHeaderTheme:
|
channelListHeaderTheme:
|
||||||
@@ -223,6 +230,8 @@ class StreamChatThemeData {
|
|||||||
messageListViewTheme: messageListViewTheme ?? this.messageListViewTheme,
|
messageListViewTheme: messageListViewTheme ?? this.messageListViewTheme,
|
||||||
channelListViewTheme: channelListViewTheme ?? this.channelListViewTheme,
|
channelListViewTheme: channelListViewTheme ?? this.channelListViewTheme,
|
||||||
userListViewTheme: userListViewTheme ?? this.userListViewTheme,
|
userListViewTheme: userListViewTheme ?? this.userListViewTheme,
|
||||||
|
messageSearchListViewTheme:
|
||||||
|
messageSearchListViewTheme ?? this.messageSearchListViewTheme,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Merge themes
|
/// Merge themes
|
||||||
@@ -248,6 +257,8 @@ class StreamChatThemeData {
|
|||||||
channelListViewTheme:
|
channelListViewTheme:
|
||||||
channelListViewTheme.merge(other.channelListViewTheme),
|
channelListViewTheme.merge(other.channelListViewTheme),
|
||||||
userListViewTheme: userListViewTheme.merge(other.userListViewTheme),
|
userListViewTheme: userListViewTheme.merge(other.userListViewTheme),
|
||||||
|
messageSearchListViewTheme:
|
||||||
|
messageSearchListViewTheme.merge(other.messageSearchListViewTheme),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -476,6 +487,9 @@ class StreamChatThemeData {
|
|||||||
userListViewTheme: UserListViewThemeData(
|
userListViewTheme: UserListViewThemeData(
|
||||||
backgroundColor: colorTheme.appBg,
|
backgroundColor: colorTheme.appBg,
|
||||||
),
|
),
|
||||||
|
messageSearchListViewTheme: MessageSearchListViewThemeData(
|
||||||
|
backgroundColor: colorTheme.appBg,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1993,7 +2007,7 @@ class UserListViewTheme extends InheritedTheme {
|
|||||||
/// ```
|
/// ```
|
||||||
static UserListViewThemeData of(BuildContext context) {
|
static UserListViewThemeData of(BuildContext context) {
|
||||||
final userListViewTheme =
|
final userListViewTheme =
|
||||||
context.dependOnInheritedWidgetOfExactType<UserListViewTheme>();
|
context.dependOnInheritedWidgetOfExactType<UserListViewTheme>();
|
||||||
return userListViewTheme?.data ??
|
return userListViewTheme?.data ??
|
||||||
StreamChatTheme.of(context).userListViewTheme;
|
StreamChatTheme.of(context).userListViewTheme;
|
||||||
}
|
}
|
||||||
@@ -2038,10 +2052,10 @@ class UserListViewThemeData with Diagnosticable {
|
|||||||
///
|
///
|
||||||
/// All the properties must be non-null.
|
/// All the properties must be non-null.
|
||||||
UserListViewThemeData lerp(
|
UserListViewThemeData lerp(
|
||||||
UserListViewThemeData a,
|
UserListViewThemeData a,
|
||||||
UserListViewThemeData b,
|
UserListViewThemeData b,
|
||||||
double t,
|
double t,
|
||||||
) =>
|
) =>
|
||||||
UserListViewThemeData(
|
UserListViewThemeData(
|
||||||
backgroundColor: Color.lerp(a.backgroundColor, b.backgroundColor, t),
|
backgroundColor: Color.lerp(a.backgroundColor, b.backgroundColor, t),
|
||||||
);
|
);
|
||||||
@@ -2057,9 +2071,118 @@ class UserListViewThemeData with Diagnosticable {
|
|||||||
@override
|
@override
|
||||||
bool operator ==(Object other) =>
|
bool operator ==(Object other) =>
|
||||||
identical(this, other) ||
|
identical(this, other) ||
|
||||||
other is UserListViewThemeData &&
|
other is UserListViewThemeData &&
|
||||||
runtimeType == other.runtimeType &&
|
runtimeType == other.runtimeType &&
|
||||||
backgroundColor == other.backgroundColor;
|
backgroundColor == other.backgroundColor;
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => backgroundColor.hashCode;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
||||||
|
super.debugFillProperties(properties);
|
||||||
|
properties.add(ColorProperty('backgroundColor', backgroundColor));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Overrides the default style of [MessageSearchListView] descendants.
|
||||||
|
///
|
||||||
|
/// See also:
|
||||||
|
///
|
||||||
|
/// * [UserListViewThemeData], which is used to configure this theme.
|
||||||
|
class MessageSearchListViewTheme extends InheritedTheme {
|
||||||
|
/// Creates a [UserListViewTheme].
|
||||||
|
///
|
||||||
|
/// The [data] parameter must not be null.
|
||||||
|
const MessageSearchListViewTheme({
|
||||||
|
Key? key,
|
||||||
|
required this.data,
|
||||||
|
required Widget child,
|
||||||
|
}) : super(key: key, child: child);
|
||||||
|
|
||||||
|
/// The configuration of this theme.
|
||||||
|
final MessageSearchListViewThemeData data;
|
||||||
|
|
||||||
|
/// The closest instance of this class that encloses the given context.
|
||||||
|
///
|
||||||
|
/// If there is no enclosing [MessageSearchListView] widget, then
|
||||||
|
/// [StreamChatThemeData.messageSearchListViewTheme] is used.
|
||||||
|
///
|
||||||
|
/// Typical usage is as follows:
|
||||||
|
///
|
||||||
|
/// ```dart
|
||||||
|
/// MessageSearchListViewTheme theme = MessageSearchListViewTheme.of(context);
|
||||||
|
/// ```
|
||||||
|
static MessageSearchListViewThemeData of(BuildContext context) {
|
||||||
|
final messageSearchListViewTheme = context
|
||||||
|
.dependOnInheritedWidgetOfExactType<MessageSearchListViewTheme>();
|
||||||
|
return messageSearchListViewTheme?.data ??
|
||||||
|
StreamChatTheme.of(context).messageSearchListViewTheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget wrap(BuildContext context, Widget child) =>
|
||||||
|
MessageSearchListViewTheme(data: data, child: child);
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool updateShouldNotify(MessageSearchListViewTheme oldWidget) =>
|
||||||
|
data != oldWidget.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A style that overrides the default appearance of [MessageSearchListView]s
|
||||||
|
/// when used with [MessageSearchListView] or with the overall
|
||||||
|
/// [StreamChatTheme]'s [StreamChatThemeData.messageSearchListViewTheme].
|
||||||
|
///
|
||||||
|
/// See also:
|
||||||
|
///
|
||||||
|
/// * [MessageSearchListViewTheme], the theme which is configured with this
|
||||||
|
/// class.
|
||||||
|
/// * [StreamChatThemeData.messageSearchListViewTheme], which can be used to
|
||||||
|
/// override the default style for [UserListView]s below the overall
|
||||||
|
/// [StreamChatTheme].
|
||||||
|
class MessageSearchListViewThemeData with Diagnosticable {
|
||||||
|
/// Creates a [MessageSearchListViewThemeData].
|
||||||
|
const MessageSearchListViewThemeData({
|
||||||
|
this.backgroundColor,
|
||||||
|
});
|
||||||
|
|
||||||
|
/// The color of the [MessageSearchListView] background.
|
||||||
|
final Color? backgroundColor;
|
||||||
|
|
||||||
|
/// Copies this [MessageSearchListViewThemeData] to another.
|
||||||
|
MessageSearchListViewThemeData copyWith({
|
||||||
|
Color? backgroundColor,
|
||||||
|
}) =>
|
||||||
|
MessageSearchListViewThemeData(
|
||||||
|
backgroundColor: backgroundColor ?? this.backgroundColor,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Linearly interpolate between two [UserListViewThemeData] themes.
|
||||||
|
///
|
||||||
|
/// All the properties must be non-null.
|
||||||
|
MessageSearchListViewThemeData lerp(
|
||||||
|
MessageSearchListViewThemeData a,
|
||||||
|
MessageSearchListViewThemeData b,
|
||||||
|
double t,
|
||||||
|
) =>
|
||||||
|
MessageSearchListViewThemeData(
|
||||||
|
backgroundColor: Color.lerp(a.backgroundColor, b.backgroundColor, t),
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Merges one [MessageSearchListViewThemeData] with another.
|
||||||
|
MessageSearchListViewThemeData merge(MessageSearchListViewThemeData? other) {
|
||||||
|
if (other == null) return this;
|
||||||
|
return copyWith(
|
||||||
|
backgroundColor: other.backgroundColor,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) =>
|
||||||
|
identical(this, other) ||
|
||||||
|
other is MessageSearchListViewThemeData &&
|
||||||
|
runtimeType == other.runtimeType &&
|
||||||
|
backgroundColor == other.backgroundColor;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get hashCode => backgroundColor.hashCode;
|
int get hashCode => backgroundColor.hashCode;
|
||||||
|
|||||||
Reference in New Issue
Block a user