基础组件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

favorite_page.dart 2.2 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import 'dart:typed_data';
  2. import 'dart:ui' as ui;
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/rendering.dart';
  5. import 'package:zhiying_comm/zhiying_comm.dart';
  6. import 'package:zhiying_base_widget/template/goods_share_template/goods_share_template.dart';
  7. import 'package:image_save/image_save.dart';
  8. class FavoritePage extends StatefulWidget {
  9. @override
  10. _FavoritePageState createState() => _FavoritePageState();
  11. }
  12. class _FavoritePageState extends State<FavoritePage> {
  13. GlobalKey globalKey = GlobalKey();
  14. @override
  15. Widget build(BuildContext context) {
  16. return Scaffold(
  17. appBar: AppBar(
  18. title: Text('收藏夹'),
  19. ),
  20. body: Column(
  21. children: <Widget>[
  22. Container(
  23. width: 100,
  24. height: 200,
  25. child: Transform.scale(
  26. scale: 0.2, child: GoodsShareTemplate(key: globalKey)),
  27. ),
  28. FlatButton(
  29. child: Icon(Icons.add),
  30. onPressed: () async {
  31. try {
  32. BuildContext buildContext = globalKey.currentContext;
  33. if (null != buildContext) {
  34. RenderRepaintBoundary boundary =
  35. buildContext.findRenderObject();
  36. var image = await boundary.toImage();
  37. ByteData byteData =
  38. await image.toByteData(format: ui.ImageByteFormat.png);
  39. // final result = await ImageGallerySaver.saveImage(
  40. // byteData.buffer.asUint8List());
  41. // var response = await Dio().get(
  42. // "https://ss0.baidu.com/94o3dSag_xI4khGko9WTAnF6hhy/image/h%3D300/sign=a62e824376d98d1069d40a31113eb807/838ba61ea8d3fd1fc9c7b6853a4e251f94ca5f46.jpg",
  43. // options: Options(responseType: ResponseType.bytes));
  44. bool success = await ImageSave.saveImageToSandbox(
  45. byteData.buffer.asUint8List(), "demo.png");
  46. print('${success}');
  47. // print(result);
  48. }
  49. cache(err) {
  50. Logger.error(err);
  51. }
  52. }
  53. },
  54. )
  55. ],
  56. ),
  57. );
  58. }
  59. }