From 3d40193f9ab0983a44c9c8a2e5e26e3815621bd2 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Thu, 23 Apr 2020 15:26:55 +0200 Subject: [PATCH] add default user image to theme --- example/lib/main.dart | 7 ------- lib/src/stream_chat.dart | 1 + lib/src/stream_chat_theme.dart | 12 ++++++++++++ lib/src/user_avatar.dart | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 80ea02b3..32af2bd3 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -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(), ), diff --git a/lib/src/stream_chat.dart b/lib/src/stream_chat.dart index 17f3ff40..258a308f 100644 --- a/lib/src/stream_chat.dart +++ b/lib/src/stream_chat.dart @@ -115,6 +115,7 @@ class StreamChatState extends State final theme = defaultTheme.copyWith( primaryColor: themeData?.primaryColor, defaultChannelImage: themeData?.defaultChannelImage, + defaultUserImage: themeData?.defaultUserImage, channelTheme: defaultTheme.channelTheme.copyWith( channelHeaderTheme: defaultTheme.channelTheme.channelHeaderTheme.copyWith( diff --git a/lib/src/stream_chat_theme.dart b/lib/src/stream_chat_theme.dart index 84f8a8f2..289f477d 100644 --- a/lib/src/stream_chat_theme.dart +++ b/lib/src/stream_chat_theme.dart @@ -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), diff --git a/lib/src/user_avatar.dart b/lib/src/user_avatar.dart index aaaa6a27..2377411e 100644 --- a/lib/src/user_avatar.dart +++ b/lib/src/user_avatar.dart @@ -43,7 +43,7 @@ class UserAvatar extends StatelessWidget { }, fit: BoxFit.cover, ) - : SizedBox(), + : StreamChatTheme.of(context).defaultUserImage(context, user), ), ); }