dice_bear
Flutter Package

DiceBear API wrapper. DiceBear is an avatar library for designers and developers. Generate random avatar profile pictures!

GitHub stars pub package

  • Checkout DiceBear
  • Checkout all avatar styles and licenses here.

Usage

Import dice_bear

import 'package:dice_bear/dice_bear.dart';

Create Avatar object

Avatar _avatar = DiceBearBuilder(
  seed: 'your-seed',               // Default seed is an empty string if you don't set it
).build();

Or generate random Avatar everytime:

Avatar _avatar = DiceBearBuilder.withRandomSeed().build();

See below for available DiceBearBuilder() Parameters

Get Uri of generated avatar SVG

Uri uri = _avatar.svgUri;

This Uri is a URL of api.dicebear.com which returns raw SVG data.

Get a Widget using Avatar

Widget image = _avatar.toImage();

See below for available toImage() parameters.

Get raw SVG bytes data

Uint8List? raw = await _avatar.asRawSvgBytes();

DiceBearBuilder() Parameters

These options affect the SVG. They do not affect the widget created by avatar.toImage(). See avatar.toImage() Parameters below.

Parameter Details Default Value Range Comment
DiceBearSprite? sprite Design of avatar to show DiceBearSprite.any See all styles
String? seed Seed for the avatar '' You can use UID of user to generate a personal avatar of that user.
Color? backgroundColor Background color No Color (May or may not be transparent, depending on selected sprite) Opacity/Alpha does not effect the background color.
int radius Radius 0 min: 0
max: 20
int size Size of SVG min: 1 This does not define the size of widget.
int scale Scale avatar inside SVG container 100 min: 0
max: 200
bool flip Flip avatar horizontally false
int rotate Number if degrees to rotate image clockwise 0 min: 0
max: 360
int translateX Translate avatar SVG along X-axis 0 min: -100
max: 100
int translateY Translate avatar SVG along Y-axis 0 min: -100
max: 100

DiceBearSprite enum

Sprite Example Comment
DiceBearSprite.any Sets a random sprite
DiceBearSprite.adventurer
DiceBearSprite.adventurerNeutral
DiceBearSprite.avataaars
DiceBearSprite.avataaarsNeutral
DiceBearSprite.bigEars
DiceBearSprite.bigEarsNeutral
DiceBearSprite.bigSmile
DiceBearSprite.bottts
DiceBearSprite.botttsNeutral
DiceBearSprite.croodles
DiceBearSprite.croodlesNeutral
DiceBearSprite.funEmoji
DiceBearSprite.icons
DiceBearSprite.identicon
DiceBearSprite.initials Deprecated because avatar.toImage()
throws an exception on this sprite
DiceBearSprite.lorelei
DiceBearSprite.loreleiNeutral
DiceBearSprite.micah
DiceBearSprite.miniavs
DiceBearSprite.openPeeps
DiceBearSprite.personas
DiceBearSprite.pixelArt
DiceBearSprite.pixelArtNeutral

avatar.toImage() Parameters

Parameter Default Value
Key? key
double? width
double? height
BoxFit fit BoxFit.contain
Alignment alignment Alignment.center
bool matchTextDirection false
bool allowDrawingOutsideViewBox false
WidgetBuilder? placeholderBuilder
Color? color
BlendMode colorBlendMode BlendMode.srcIn
String? semanticsLabel
bool excludeFromSemantics false
Clip clipBehavior Clip.hardEdge
bool cacheColorFilter false
SvgTheme? theme

Libraries

dice_bear