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.

69 lines
1.6KB

  1. import 'package:flutter/material.dart';
  2. import 'package:shimmer/shimmer.dart';
  3. class ShimmerImage extends StatelessWidget {
  4. String url;
  5. BoxFit fit;
  6. double width;
  7. double height;
  8. double aspectRatio;
  9. double iconHolderSize = 40;
  10. ShimmerImage(
  11. this.url, {
  12. this.fit,
  13. this.width,
  14. this.height,
  15. this.aspectRatio,
  16. this.iconHolderSize,
  17. });
  18. @override
  19. Widget build(BuildContext context) {
  20. return Stack(
  21. children: <Widget>[
  22. Shimmer.fromColors(
  23. baseColor: Colors.grey[200],
  24. highlightColor: Colors.grey[100],
  25. child: this.aspectRatio != null
  26. ? AspectRatio(
  27. aspectRatio: aspectRatio,
  28. child: Container(
  29. child: _buildIcon(),
  30. ),
  31. )
  32. : Container(
  33. width: this.width,
  34. height: this.height,
  35. child: _buildIcon(),
  36. ),
  37. ),
  38. this.aspectRatio != null
  39. ? AspectRatio(
  40. aspectRatio: aspectRatio,
  41. child: Image.network(
  42. url,
  43. fit: fit ?? BoxFit.contain,
  44. ),
  45. )
  46. : Image.network(
  47. url,
  48. width: this.width,
  49. height: this.height,
  50. fit: fit ?? BoxFit.contain,
  51. ),
  52. ],
  53. );
  54. }
  55. _buildIcon() {
  56. return Center(
  57. child: Icon(
  58. Icons.crop_original,
  59. color: Colors.red,
  60. size: iconHolderSize,
  61. ),
  62. );
  63. }
  64. }