Flutter 头像 - Bottts

一个高性能的Flutter小部件,用于在Android/iOS设备上渲染Bottts svg头像。

它比其他传统方法更快,因为它不使用任何 API,而是实时渲染 SVG 字符串!

Bottts

dark-theme

Bottts

角色最初由 Pablo Stanley 设计,Sketch 库可以在 bottts.com 上找到。

入门

  1. 创建 Bottt 对象
// Create Bottt with default constructor
var _bottt = Bottt(
    color: Colors.red,
    eye: EyeType.Glow,
    face: FaceType.Square03,
    mouth: MouthType.Bite,
    side: SideType.Round,
    texture: TextureType.Dirty01,
    top: TopType.Horns,
);

// Randomize all properties
var _bottt = Bottt.random();

// Or keep some properties specific & remaining as random
var _bottt = Bottt.random(
  top: TopType.Horns,
  mouth: MouthType.Bite,
);
  1. 创建 BotttAvatar 组件并传递 Bottt 对象
Padding(
    padding: EdgeInsets.all(20),
    child: BotttAvatar(_bottt),
)

// Alternatively you can also combine the widget with a CircleAvatar
CircleAvatar(
    radius: 90,
    child: CircleAvatar(
    radius: 85,
    backgroundColor: Color.fromARGB(255, 100, 100, 100),
    child: Padding(
        padding: EdgeInsets.all(20),
        child: BotttAvatar(_bottt),
    ),
    ),
)

序列化/反序列化

对于 Maps:使用 botttObject.toJson()Bottt.fromJson(serializedBotttString) 方法进行序列化/反序列化。

对于 Strings:使用 botttObject.serialize()Bottt.deserialize()(serializedBotttString) 方法进行序列化/反序列化。

GitHub

https://github.com/AbhijatSaxena/flutter_avatars_bottts