CircleImage.dart 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import 'package:flutter/material.dart';
  2. enum CircleImageType { network, asset }
  3. class CircleImage extends StatefulWidget {
  4. double width;
  5. double height;
  6. String path;
  7. CircleImageType type; // network, asset
  8. CircleImage(
  9. {required this.width,
  10. required this.height,
  11. required this.path,
  12. required this.type});
  13. @override
  14. State<StatefulWidget> createState() {
  15. return CircleImageState();
  16. }
  17. }
  18. class CircleImageState extends State<CircleImage> {
  19. @override
  20. Widget build(BuildContext context) {
  21. var img;
  22. if (widget.type == CircleImageType.network) {
  23. img = Image.network(widget.path,
  24. width: widget.width, height: widget.height);
  25. } else {
  26. img =
  27. Image.asset(widget.path, width: widget.width, height: widget.height);
  28. }
  29. return Container(
  30. width: widget.width,
  31. height: widget.height,
  32. decoration: BoxDecoration(
  33. shape: BoxShape.circle,
  34. color: Colors.blue,
  35. image: DecorationImage(image: img, fit: BoxFit.cover),
  36. border: Border.all(
  37. color: Colors.white,
  38. width: 2.0,
  39. ),
  40. ),
  41. );
  42. }
  43. }