Skip to main content

Avatar

CometChatAvatar component displays an image or user's avatar with fallback to the first two letters of the username or group's icon with fallback to the first two letter of the group name.


How to integrate CometChatAvatar ?

CometChatAvataris an stateless widget that can be added directly to your build method

CometChatAvatar(
image: "<image_url>", // Replace it with asset image url
name: "<name>" // Replace it with name
);

Properties

PropertiesTypeDescription
imageStringimage will be obtained from path from assets.

if name and image both are passed image will be visible
nameStringused to can specify name to be shown in avatar (initials only), if image is not available
styleAvatarStyleused to customize appearance of the Avatar

AvatarStyle

PropertiesTypeDescription
heightdoubleused to set height
widthdoubleused to set width
borderBoxBorderused to set border of the inner circle
backgroundColorused to set background color
gradientGradientused to set a gradient background
borderRadiusdoubleused to modify the corner radius of inner circle
outerBorderRadiusdoubleused to modify the corner radius of outer circle
outerViewBorderBoxBorderused to modify the border of outer circle
outerViewWidthdoubleused to modify the border width of outer circle
outerViewBackgroundColorColorused to modify the background color of outer circle
outerViewSpacingdoubleused to modify spacing between the image and the outer border
nameTextStyleTextStyleused to modify the text style for name if image is not available

Usage

CometChatAvatar(
image: "https://data-us.cometchat.io/assets/images/avatars/spiderman.png",
name: "Spidey",
style: AvatarStyle(
width: 36,
height: 36,
background: Colors.blue,
borderRadius: 16,
outerBorderRadius: 16,
border: Border.all(
color: Colors.amber,
width: 1,
),
outerViewBackgroundColor: Colors.teal,
nameTextStyle: TextStyle(fontSize: 20),
outerViewBorder: Border.all(
color: Colors.pink,
width: 1,
),
outerViewSpacing: 2,
outerViewWidth: null,
)
);