No Description

asset_image.dart 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. print(
  22. "assetEntity.width = ${assetEntity.width} , assetEntity.height = ${assetEntity.height}");
  23. return FutureBuilder<Uint8List>(
  24. builder: (BuildContext context, snapshot) {
  25. if (snapshot.hasData) {
  26. return _buildContainer(
  27. child: Image.memory(
  28. snapshot.data,
  29. width: width,
  30. height: height,
  31. fit: boxFit,
  32. ),
  33. );
  34. } else {
  35. return _buildContainer();
  36. }
  37. },
  38. future: assetEntity.thumbDataWithSize(
  39. width.toInt(),
  40. height.toInt(),
  41. ),
  42. );
  43. }
  44. Widget _buildContainer({Widget child}) {
  45. child ??= Container();
  46. return Container(
  47. width: width,
  48. height: height,
  49. child: child,
  50. );
  51. }
  52. }