add default user image to theme
This commit is contained in:
@@ -28,13 +28,6 @@ class MyApp extends StatelessWidget {
|
||||
themeMode: ThemeMode.system,
|
||||
home: Container(
|
||||
child: StreamChat(
|
||||
streamChatThemeData: StreamChatThemeData(
|
||||
defaultChannelImage: (context, channel) {
|
||||
return Center(
|
||||
child: Text('AAA'),
|
||||
);
|
||||
},
|
||||
),
|
||||
client: client,
|
||||
child: ChannelListPage(),
|
||||
),
|
||||
|
||||
@@ -115,6 +115,7 @@ class StreamChatState extends State<StreamChat>
|
||||
final theme = defaultTheme.copyWith(
|
||||
primaryColor: themeData?.primaryColor,
|
||||
defaultChannelImage: themeData?.defaultChannelImage,
|
||||
defaultUserImage: themeData?.defaultUserImage,
|
||||
channelTheme: defaultTheme.channelTheme.copyWith(
|
||||
channelHeaderTheme:
|
||||
defaultTheme.channelTheme.channelHeaderTheme.copyWith(
|
||||
|
||||
@@ -54,6 +54,9 @@ class StreamChatThemeData {
|
||||
/// The widget that will be built when the channel image is unavailable
|
||||
final Widget Function(BuildContext, Channel) defaultChannelImage;
|
||||
|
||||
/// The widget that will be built when the user image is unavailable
|
||||
final Widget Function(BuildContext, User) defaultUserImage;
|
||||
|
||||
/// Create a theme from scratch
|
||||
StreamChatThemeData({
|
||||
this.primaryColor,
|
||||
@@ -64,6 +67,7 @@ class StreamChatThemeData {
|
||||
this.otherMessageTheme,
|
||||
this.ownMessageTheme,
|
||||
this.defaultChannelImage,
|
||||
this.defaultUserImage,
|
||||
});
|
||||
|
||||
/// Create a theme from a Material [Theme]
|
||||
@@ -103,12 +107,14 @@ class StreamChatThemeData {
|
||||
MessageTheme ownMessageTheme,
|
||||
MessageTheme otherMessageTheme,
|
||||
Widget Function(BuildContext, Channel) defaultChannelImage,
|
||||
Widget Function(BuildContext, User) defaultUserImage,
|
||||
}) =>
|
||||
StreamChatThemeData(
|
||||
primaryColor: primaryColor ?? this.primaryColor,
|
||||
secondaryColor: secondaryColor ?? this.secondaryColor,
|
||||
accentColor: accentColor ?? this.accentColor,
|
||||
defaultChannelImage: defaultChannelImage ?? this.defaultChannelImage,
|
||||
defaultUserImage: defaultUserImage ?? this.defaultUserImage,
|
||||
channelPreviewTheme: channelPreviewTheme?.copyWith(
|
||||
title:
|
||||
channelPreviewTheme.title ?? this.channelPreviewTheme.title,
|
||||
@@ -178,6 +184,12 @@ class StreamChatThemeData {
|
||||
accentColor: accentColor,
|
||||
primaryColor: isDark ? Colors.black : Colors.white,
|
||||
defaultChannelImage: (context, channel) => SizedBox(),
|
||||
defaultUserImage: (context, user) => Center(
|
||||
child: Text(
|
||||
user.name?.substring(0, 1) ?? '',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
channelPreviewTheme: ChannelPreviewTheme(
|
||||
avatarTheme: AvatarTheme(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
|
||||
@@ -43,7 +43,7 @@ class UserAvatar extends StatelessWidget {
|
||||
},
|
||||
fit: BoxFit.cover,
|
||||
)
|
||||
: SizedBox(),
|
||||
: StreamChatTheme.of(context).defaultUserImage(context, user),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user