dice_bear
Flutter 包
DiceBear API 包装器。DiceBear 是一个面向设计师和开发者的头像库。生成随机
头像个人资料图片!
用法
- 导入 dice_bear
- 创建 Avatar 对象
- 获取生成头像 SVG 的 URI
- 使用 Avatar 获取 Widget
- 获取原始 SVG 字节数据
- DiceBearBuilder() 参数
- DiceBearSprite 枚举
- avatar.toImage() 参数
导入 dice_bear
import 'package:dice_bear/dice_bear.dart';
创建 Avatar 对象
Avatar _avatar = DiceBearBuilder(
seed: 'your-seed', // Default seed is an empty string if you don't set it
).build();
或者每次都生成随机的 Avatar
Avatar _avatar = DiceBearBuilder.withRandomSeed().build();
有关可用的 DiceBearBuilder() 参数,请参阅下方。
获取生成头像 SVG 的 URI
Uri uri = _avatar.svgUri;
此 URI 是 api.dicebear.com 的 URL,它返回原始 SVG 数据。
使用 Avatar 获取 Widget
Widget image = _avatar.toImage();
有关 toImage() 参数,请参阅下方。
获取原始 SVG 字节数据
Uint8List? raw = await _avatar.asRawSvgBytes();
DiceBearBuilder() 参数
这些选项会影响 SVG。它们不会影响由 avatar.toImage() 创建的小部件。请参阅下方的 avatar.toImage() 参数。
| 参数 | 详情 | 默认值 | 范围 | 注释 |
|---|---|---|---|---|
DiceBearSprite? sprite |
要显示的头像设计 | DiceBearSprite.any |
查看所有样式 | |
String? seed |
头像的种子 | '' |
您可以使用用户的 UID 为该用户生成个人头像。 | |
Color? backgroundColor |
背景颜色 | 无颜色(透明) | 不透明度/Alpha 不会影响背景颜色。 | |
int radius |
Radius | 0 |
最小: 0 最大: 20 |
|
int size |
SVG 的大小 | 最小: 1 | 这不会定义小部件的大小。 | |
int scale |
在 SVG 容器内缩放头像 | 100 |
最小: 0 最大: 200 |
|
bool flip |
水平翻转头像 | 假 |
||
int rotate |
顺时针旋转图像的度数 | 0 |
最小: 0 最大: 360 |
|
int translateX |
沿 X 轴平移头像 SVG | 0 |
最小: -100 最大: 100 |
|
int translateY |
沿 Y 轴平移头像 SVG | 0 |
最小: -100 最大: 100 |
DiceBearSprite 枚举
avatar.toImage() 参数
| 参数 | 默认值 |
|---|---|
Key? key |
|
double? width |
|
double? height |
|
BoxFit fit |
BoxFit.contain |
Alignment alignment |
Alignment.center |
bool matchTextDirection |
假 |
bool allowDrawingOutsideViewBox |
假 |
WidgetBuilder? placeholderBuilder |
|
Color? color |
|
BlendMode colorBlendMode |
BlendMode.srcIn |
String? semanticsLabel |
|
bool excludeFromSemantics |
假 |
Clip clipBehavior |
Clip.hardEdge |
bool cacheColorFilter |
假 |
SvgTheme? theme |