item_following.dart 3.8 KB

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