CircleImage.dart 1.1 KB

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