Brak opisu

asset_image.dart 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import 'dart:typed_data';
  2. import 'package:flutter/material.dart';
  3. import 'package:photo_manager/photo_manager.dart';
  4. class AssetImageWidget extends StatelessWidget {
  5. final AssetEntity assetEntity;
  6. final double width;
  7. final double height;
  8. final BoxFit boxFit;
  9. const AssetImageWidget({
  10. Key key,
  11. @required this.assetEntity,
  12. this.width,
  13. this.height,
  14. this.boxFit,
  15. }) : super(key: key);
  16. @override
  17. Widget build(BuildContext context) {
  18. if (assetEntity == null) {
  19. return _buildContainer();
  20. }
  21. final size = assetEntity.size;
  22. print(
  23. "assetEntity.width = ${assetEntity.width} , assetEntity.height = ${assetEntity.height}");
  24. return FutureBuilder<Uint8List>(
  25. builder: (BuildContext context, snapshot) {
  26. if (snapshot.hasData) {
  27. return _buildContainer(
  28. child: Image.memory(
  29. snapshot.data,
  30. width: width,
  31. height: height,
  32. fit: boxFit,
  33. ),
  34. );
  35. } else {
  36. return _buildContainer();
  37. }
  38. },
  39. future: assetEntity.thumbDataWithSize(
  40. width.toInt(),
  41. height.toInt(),
  42. ),
  43. );
  44. }
  45. Widget _buildContainer({Widget child}) {
  46. child ??= Container();
  47. return Container(
  48. width: width,
  49. height: height,
  50. child: child,
  51. );
  52. }
  53. }