item_following.dart 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import 'package:cpt_community/components/comments_dialog.dart';
  2. import 'package:cpt_community/modules/my_following/my_follow/my_follow_vm.dart';
  3. import 'package:cpt_community/modules/my_following/my_follower/my_follower_vm.dart';
  4. import 'package:cs_resources/generated/l10n.dart';
  5. import 'package:cs_resources/theme/app_colors_theme.dart';
  6. import 'package:flutter/cupertino.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:flutter_hooks/flutter_hooks.dart';
  9. import 'package:flutter_riverpod/flutter_riverpod.dart';
  10. import 'package:hooks_riverpod/hooks_riverpod.dart';
  11. import 'package:shared/utils/log_utils.dart';
  12. import 'package:widgets/ext/ex_widget.dart';
  13. import 'package:widgets/my_button.dart';
  14. import 'package:widgets/my_load_image.dart';
  15. import 'package:widgets/my_text_view.dart';
  16. import 'item_following_vm.dart';
  17. class MyFollowingListItem extends StatelessWidget {
  18. final String itemType;
  19. bool? hasBottomDriver = true;
  20. Map<String, dynamic> itemObj;
  21. void Function(dynamic)? onClickAction;
  22. MyFollowingListItem({
  23. super.key,
  24. required this.itemObj,
  25. itemType,
  26. this.hasBottomDriver=true,
  27. this.onClickAction
  28. }): itemType = itemType ?? MyFollowingType['isFollowType'];
  29. @override
  30. Widget build(BuildContext context) {
  31. String avator = itemObj?['avatar']??'';
  32. String name = itemObj?['name']??'';
  33. return Column(
  34. children: [
  35. Container(
  36. margin: const EdgeInsets.only(left: 15,right: 15,top: 15,bottom: 15),
  37. child: Row(
  38. mainAxisSize: MainAxisSize.max,
  39. children: [
  40. Expanded(
  41. child: Row(
  42. mainAxisAlignment: MainAxisAlignment.start,
  43. children: [
  44. MyLoadImage(
  45. avator,
  46. width: 65,
  47. height: 65,
  48. isCircle: true,
  49. ),
  50. MyTextView(
  51. name,
  52. fontSize: 17,
  53. isFontMedium: true,
  54. marginLeft: 17,
  55. )
  56. ],
  57. ).onTap((){
  58. // onClickAction?.call(itemObj);
  59. }),
  60. ),
  61. // _buildIsFollowButton(context),
  62. itemType == MyFollowingType['isFollowType'] ? HookConsumer(
  63. key: ValueKey(itemObj['id']), // 唯一标识每个 item
  64. builder: (context, ref, child) {
  65. final isFollow = useState<bool>(true);
  66. return MyButton(
  67. text: isFollow.value? S.current.followed : S.current.to_follow,
  68. onPressed: () async{
  69. final vm = ref.read(itemFollowingVmProvider.notifier);
  70. // todo 调用接口 然后更新状态
  71. int to_user_id = itemObj['id'];
  72. vm.handlerFollow(context, to_user_id, isFollow.value, itemType!, (asyncResult){
  73. if(asyncResult){
  74. isFollow.value = !isFollow.value;
  75. }
  76. });
  77. },
  78. textColor: isFollow.value? context.appColors.textDarkGray : context.appColors.textWhite,
  79. side: isFollow.value? BorderSide(color: context.appColors.textDarkGray,width: 0.5) : BorderSide.none,
  80. backgroundColor: isFollow.value? Colors.transparent :context.appColors.textPrimary,
  81. fontSize: 14,
  82. fontWeight: FontWeight.w400,
  83. minWidth: 67.5,
  84. minHeight: 30.5,
  85. );
  86. },
  87. ): const SizedBox.shrink()
  88. ],
  89. ),
  90. ),
  91. if(hasBottomDriver!)
  92. Container(
  93. height: 1,
  94. color: context.appColors.dividerDefault,
  95. )
  96. ],
  97. );
  98. }
  99. }