widget2image

Creator: coderz1093

Last updated:

0 purchases

TODO
Add to Cart

Description:

widget2image

使用: #
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Widget2Image( // <--- 包裹需要变成图片的组件
format: ImageByteFormat.png,
child: Container(
alignment: Alignment.center,
height: 200,
width: 200,
color: Colors.red,
child: Builder(
builder: (ctx) => IconButton(
icon: const Icon(Icons.ac_unit),
onPressed: () => _loadImage(ctx),
),
),
),
);
}

void _loadImage(BuildContext context) async {
// 获取图片字节 ,注意需要 Widget2Image 下方的上下文
var bytes = await Widget2Image.of(context).loadImage();
print(bytes);
// 获取到图片字节数据 ---- 之后可随意操作
// final dir = await getTemporaryDirectory();
// final dest = path.join(dir.path, "widget.png");
// await File(dest).writeAsBytes(bytes);
// Scaffold.of(context).showSnackBar(SnackBar(content: Text("图片已保存到:$dest")));
}
}
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files:

Customer Reviews

There are no reviews.