CircleImage.dart 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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({@required this.width, @required this.height, @required this.path, @required this.type});
  9. @override
  10. State<StatefulWidget> createState() {
  11. return null;
  12. }
  13. }
  14. class CircleImageState extends State<CircleImage> {
  15. @override
  16. Widget build(BuildContext context) {
  17. var img;
  18. if (widget.type == CircleImageType.network) {
  19. img = Image.network(widget.path, width: widget.width, height: widget.height);
  20. } else {
  21. img = Image.asset(widget.path, width: widget.width, height: widget.height);
  22. }
  23. return Container(
  24. width: widget.width,
  25. height: widget.height,
  26. decoration: BoxDecoration(
  27. shape: BoxShape.circle,
  28. color: Colors.blue,
  29. image: DecorationImage(
  30. image: img,
  31. fit: BoxFit.cover
  32. ),
  33. border: Border.all(
  34. color: Colors.white,
  35. width: 2.0,
  36. ),
  37. ),
  38. );
  39. }
  40. }