dice_bear 0.1.2 dice_bear: ^0.1.2 copied to clipboard
DiceBear API wrapper. DiceBear is an avatar library for designers and developers. Generate random avatar profile pictures!
dice_bear
Flutter Package
DiceBear API wrapper. DiceBear is an avatar library for designers and developers. Generate random avatar profile pictures!
Usage #
- Import dice_bear
- Create Avatar object
- Get Uri of generated avatar SVG
- Get a Widget using Avatar
- Get raw SVG bytes data
- DiceBearBuilder() Parameters
- DiceBearSprite enum
- avatar.toImage() Parameters
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.
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 (Transparent) | 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.bigEars |
||
DiceBearSprite.bigEarsNeutral |
||
DiceBearSprite.bigSmile |
||
DiceBearSprite.bottts |
||
DiceBearSprite.croodles |
||
DiceBearSprite.croodlesNeutral |
||
DiceBearSprite.identicon |
||
DiceBearSprite.initials |
Deprecated because avatar.toImage() throws an exception on this sprite |
|
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 |