import 'dart:typed_data'; import 'dart:ui' as ui; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; import 'package:zhiying_base_widget/template/goods_share_template/goods_share_template.dart'; import 'package:image_save/image_save.dart'; class FavoritePage extends StatefulWidget { @override _FavoritePageState createState() => _FavoritePageState(); } class _FavoritePageState extends State { GlobalKey globalKey = GlobalKey(); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('收藏夹'), ), body: Column( children: [ Container( width: 100, height: 200, child: Transform.scale( scale: 0.2, child: GoodsShareTemplate(key: globalKey)), ), FlatButton( child: Icon(Icons.add), onPressed: () async { try { BuildContext buildContext = globalKey.currentContext; if (null != buildContext) { RenderRepaintBoundary boundary = buildContext.findRenderObject(); var image = await boundary.toImage(); ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.png); // final result = await ImageGallerySaver.saveImage( // byteData.buffer.asUint8List()); // var response = await Dio().get( // "https://ss0.baidu.com/94o3dSag_xI4khGko9WTAnF6hhy/image/h%3D300/sign=a62e824376d98d1069d40a31113eb807/838ba61ea8d3fd1fc9c7b6853a4e251f94ca5f46.jpg", // options: Options(responseType: ResponseType.bytes)); bool success = await ImageSave.saveImageToSandbox( byteData.buffer.asUint8List(), "demo.png"); print('${success}'); // print(result); } cache(err) { Logger.error(err); } } }, ) ], ), ); } }