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 effect the SVG. They does not effect the widget created by avatar.toImage(). See avatar.toImage() Parameters below.

ParameterDetailsDefault ValueRangeComment
DiceBearSprite? spriteDesign of avatar to showDiceBearSprite.anySee all styles
String? seedSeed for the avatar''You can use UID of user to generate a personal avatar of that user.
Color? backgroundColorBackground colorNo Color (May or may not be transparent, depending on selected sprite)Opacity/Alpha does not effect the background color.
int radiusRadius0min: 0
max: 20
int sizeSize of SVGmin: 1This does not define the size of widget.
int scaleScale avatar inside SVG container100min: 0
max: 200
bool flipFlip avatar horizontallyfalse
int rotateNumber if degrees to rotate image clockwise0min: 0
max: 360
int translateXTranslate avatar SVG along X-axis0min: -100
max: 100
int translateYTranslate avatar SVG along Y-axis0min: -100
max: 100

DiceBearSprite enum

SpriteExampleComment
DiceBearSprite.anySets a random sprite
DiceBearSprite.adventurer
DiceBearSprite.adventurerNeutral
DiceBearSprite.avataaars
DiceBearSprite.bigEars
DiceBearSprite.bigEarsNeutral
DiceBearSprite.bigSmile
DiceBearSprite.bottts
DiceBearSprite.croodles
DiceBearSprite.croodlesNeutral
DiceBearSprite.identicon
DiceBearSprite.initialsDeprecated because avatar.toImage()
throws an exception on this sprite
DiceBearSprite.micah
DiceBearSprite.miniavs
DiceBearSprite.openPeeps
DiceBearSprite.personas
DiceBearSprite.pixelArt
DiceBearSprite.pixelArtNeutral

avatar.toImage() Parameters

ParameterDefault Value
Key? key
double? width
double? height
BoxFit fitBoxFit.contain
Alignment alignmentAlignment.center
bool matchTextDirectionfalse
bool allowDrawingOutsideViewBoxfalse
WidgetBuilder? placeholderBuilder
Color? color
BlendMode colorBlendModeBlendMode.srcIn
String? semanticsLabel
bool excludeFromSemanticsfalse
Clip clipBehaviorClip.hardEdge
bool cacheColorFilterfalse
SvgTheme? theme

Libraries

dice_bear