avatar_builder_core 0.2.0
avatar_builder_core: ^0.2.0 copied to clipboard
Pure Dart library for building avataaars-style cartoon avatars from customizable attributes using SVG. No Flutter dependency.
Avatar Builder Core #
A pure Dart library for building avataaars-style cartoon avatars as SVG strings. No Flutter dependency — works on servers, CLI tools, and any Dart environment.
Features #
- Pure Dart — no Flutter or
dart:uidependency - 140+ SVG fragments composable into millions of unique avatars
- Pluggable asset loading via
AssetLoadertypedef — use filesystem, HTTP, or any custom source - Random avatar generation via
Avataaar.random() - JSON serialisation with
toJson()/fromJson() - Full customisation: hair, eyes, eyebrows, mouth, facial hair, clothing, accessories, skin color
Getting started #
dependencies:
avatar_builder_core: ^0.2.0
Usage #
import 'dart:io';
import 'package:avatar_builder_core/avatar_builder_core.dart';
// Provide an AssetLoader that reads SVG fragments from disk.
Future<String> loadAsset(String key) async {
if (key.isEmpty) return '';
return File('path/to/assets/$key').readAsString();
}
void main() async {
// Create a specific avatar
final avatar = Avataaar(
topType: TopType.shortHairShortFlat,
eyeType: EyeType.happy,
mouthType: MouthType.smile,
skinColor: SkinColor.light.color,
);
// Or generate a random one
final random = Avataaar.random();
// Render to SVG string
final svg = await avatar.toSvg(loadAsset: loadAsset);
File('avatar.svg').writeAsStringSync(svg);
// Serialise to/from JSON
final json = avatar.toJson();
final restored = Avataaar.fromJson(json);
}
For Flutter apps, use the
avatar_builderpackage which providesAvatarWidgetand built-in asset loading.
Customisation options #
| Category | Enum | Options |
|---|---|---|
| Style | AvatarStyle |
circle, transparent |
| Hair / Hat | TopType |
34 styles |
| Hair color | HairColor |
12 colors |
| Accessories | AccessoriesType |
7 types |
| Facial hair | FacialHairType |
6 types |
| Eyes | EyeType |
12 styles |
| Eyebrows | EyebrowType |
13 styles |
| Mouth | MouthType |
12 styles |
| Clothing | ClotheType |
9 types |
| Clothing color | ClotheColor |
15 colors |
| Graphic (on shirts) | GraphicType |
11 designs |
| Skin | SkinColor |
7 tones |
License #
BSD 2-Clause License — see LICENSE for details.