user_header.dart 890 B

12345678910111213141516171819202122232425262728293031323334
  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:eitc_erm_app/utils/logger.dart';
  3. import 'package:flutter/material.dart';
  4. import 'image_error.dart';
  5. ///用户头像
  6. class UserHeader extends StatelessWidget {
  7. final String url;
  8. final double radius;
  9. final Widget? placeHolder;
  10. const UserHeader(
  11. {super.key, this.url = "", this.radius = 30, this.placeHolder});
  12. @override
  13. Widget build(BuildContext context) {
  14. return CircleAvatar(
  15. radius: radius,
  16. backgroundColor: Colors.transparent,
  17. foregroundImage: CachedNetworkImageProvider(url),
  18. onForegroundImageError: (e, stack) {
  19. loge("图片加载异常,url=$url", error: "$e");
  20. },
  21. child: placeHolder ??
  22. const ImageError(
  23. icon: Icons.account_circle,
  24. size: 60,
  25. color: Colors.grey,
  26. ),
  27. );
  28. }
  29. }