intimacy_user_widget.dart 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import 'package:flutter/cupertino.dart';
  2. import '../../../resource/assets.gen.dart';
  3. import '../../../resource/colors.gen.dart';
  4. import '../../../widget/avatar/avatar_image_widget.dart';
  5. /// 亲密用户组件,包含2个头像和中间一个心形图标
  6. class IntimacyUserWidget extends StatelessWidget {
  7. /// 组件的宽度
  8. final double width;
  9. /// 组件的高度
  10. final double height;
  11. /// 头像的大小
  12. final double avatarSize;
  13. /// 头像的边框宽度
  14. final double avatarBorderWidth;
  15. /// 爱心的大小
  16. final double loveSize;
  17. /// 用户1的头像
  18. final String avatarUrl1;
  19. /// 用户2的头像
  20. final String avatarUrl2;
  21. const IntimacyUserWidget({
  22. super.key,
  23. required this.width,
  24. required this.height,
  25. required this.avatarSize,
  26. required this.avatarBorderWidth,
  27. required this.loveSize,
  28. required this.avatarUrl1,
  29. required this.avatarUrl2,
  30. });
  31. @override
  32. Widget build(BuildContext context) {
  33. return SizedBox(
  34. width: width,
  35. height: height,
  36. child: Stack(
  37. // 默认内容都居中
  38. alignment: Alignment.center,
  39. children: [
  40. // 用户1
  41. Positioned(
  42. left: 0,
  43. child: _buildAvatar(
  44. avatarUrl1,
  45. defaultImage: Assets.images.iconDefaultAvatarMale.image().image,
  46. ),
  47. ),
  48. // 用户2
  49. Positioned(
  50. // 距离左侧的距离
  51. left: avatarSize - (avatarBorderWidth * 2),
  52. top: 0,
  53. child: _buildAvatar(
  54. avatarUrl2,
  55. defaultImage: Assets.images.iconDefaultAvatarFemale.image().image,
  56. ),
  57. ),
  58. // 爱心
  59. Positioned(
  60. child: Assets.images.iconIntimacyAnalyseLove.image(
  61. width: loveSize,
  62. height: loveSize,
  63. ),
  64. ),
  65. ],
  66. ),
  67. );
  68. }
  69. /// 圆形头像
  70. Widget _buildAvatar(String? imageUrl, {ImageProvider? defaultImage}) {
  71. return CircleAvatarWidget(
  72. imageUrl: imageUrl,
  73. placeholderImage: defaultImage,
  74. borderColor: ColorName.white,
  75. borderWidth: avatarBorderWidth,
  76. backgroundColor: ColorName.white,
  77. size: avatarSize,
  78. );
  79. }
  80. }