item_following.dart 3.8 KB

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