user_avatat.dart 1.3 KB

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