user_avatat.dart 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/rendering.dart';
  3. class UserAvatar extends StatelessWidget {
  4. final bool isNetwork;
  5. final String image;
  6. final VoidCallback onPressed;
  7. final double width;
  8. final double height;
  9. final EdgeInsetsGeometry padding;
  10. UserAvatar(
  11. {this.isNetwork, this.image, this.onPressed, this.width = 30.0, this.height = 30.0, this.padding});
  12. @override
  13. Widget build(BuildContext context) {
  14. return RawMaterialButton(
  15. materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
  16. padding: padding ?? EdgeInsets.only(top: 4.0, right: 5.0, left: 5.0),
  17. constraints: BoxConstraints(minWidth: 0.0, minHeight: 0.0),
  18. child: ClipRRect(
  19. borderRadius: BorderRadius.all(Radius.circular(5.0)),
  20. child: this.isNetwork ?
  21. FadeInImage.assetNetwork(
  22. placeholder: 'assets/images/temporary/avator2.png',
  23. //预览图
  24. fit: BoxFit.fitWidth,
  25. image: image,
  26. width: width,
  27. height: height,
  28. )
  29. :Image.asset(
  30. image,
  31. fit: BoxFit.cover,
  32. width: width,
  33. height: height,
  34. ),
  35. ),
  36. onPressed: onPressed
  37. );
  38. }
  39. }