Skip to content

Commit

Permalink
Add support for AssetImage in IOConditional (#619)
Browse files Browse the repository at this point in the history
* Add support for AssetImage in IOConditional

* Support for asset urls for avatar images

---------

Co-authored-by: Thomas Schweitzer <[email protected]>
  • Loading branch information
thomers and Thomas Schweitzer authored Aug 12, 2024
1 parent a2a3300 commit 8bf20ee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/src/conditional/io_conditional.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class IOConditional extends BaseConditional {
ImageProvider getProvider(String uri, {Map<String, String>? headers}) {
if (uri.startsWith('http')) {
return NetworkImage(uri, headers: headers);
} else if (uri.startsWith('assets/')) {
return AssetImage(uri);
} else {
return FileImage(File(uri));
}
Expand Down
6 changes: 5 additions & 1 deletion lib/src/widgets/message/user_avatar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter_chat_types/flutter_chat_types.dart' as types;
import '../../models/bubble_rtl_alignment.dart';
import '../../util.dart';
import '../state/inherited_chat_theme.dart';
import '../../conditional/conditional.dart';

/// Renders user's avatar or initials next to a message.
class UserAvatar extends StatelessWidget {
Expand Down Expand Up @@ -50,7 +51,10 @@ class UserAvatar extends StatelessWidget {
.userAvatarImageBackgroundColor
: color,
backgroundImage: hasImage
? NetworkImage(author.imageUrl!, headers: imageHeaders)
? Conditional().getProvider(
author.imageUrl!,
headers: imageHeaders,
)
: null,
radius: 16,
child: !hasImage
Expand Down

0 comments on commit 8bf20ee

Please sign in to comment.