diff --git a/lib/pages/follow/widgets/follow_item.dart b/lib/pages/follow/widgets/follow_item.dart index 18d13c5a..e6dbbef1 100644 --- a/lib/pages/follow/widgets/follow_item.dart +++ b/lib/pages/follow/widgets/follow_item.dart @@ -9,7 +9,14 @@ import 'package:PiliPlus/utils/utils.dart'; class FollowItem extends StatelessWidget { final FollowItemModel item; final FollowController? ctr; - const FollowItem({super.key, required this.item, this.ctr}); + final ValueChanged? callback; + + const FollowItem({ + super.key, + required this.item, + this.callback, + this.ctr, + }); @override Widget build(BuildContext context) { @@ -41,31 +48,34 @@ class FollowItem extends StatelessWidget { overflow: TextOverflow.ellipsis, ), dense: true, - trailing: ctr != null && ctr!.isOwner.value + trailing: ctr?.isOwner.value == true ? SizedBox( height: 34, - child: TextButton( + child: FilledButton.tonal( onPressed: () { Utils.actionRelationMod( context: context, mid: item.mid, - isFollow: true, - callback: (attribute) {}, + isFollow: item.attribute != -1, + callback: callback, ); }, - style: TextButton.styleFrom( + style: FilledButton.styleFrom( padding: const EdgeInsets.fromLTRB(15, 0, 15, 0), - foregroundColor: Theme.of(context).colorScheme.outline, - backgroundColor: - Theme.of(context).colorScheme.onInverseSurface, + foregroundColor: item.attribute == -1 + ? null + : Theme.of(context).colorScheme.outline, + backgroundColor: item.attribute == -1 + ? null + : Theme.of(context).colorScheme.onInverseSurface, ), - child: const Text( - '已关注', + child: Text( + '${item.attribute == -1 ? '' : '已'}关注', style: TextStyle(fontSize: 12), ), ), ) - : const SizedBox(), + : null, ); } } diff --git a/lib/pages/follow/widgets/owner_follow_list.dart b/lib/pages/follow/widgets/owner_follow_list.dart index 327c4197..6860899d 100644 --- a/lib/pages/follow/widgets/owner_follow_list.dart +++ b/lib/pages/follow/widgets/owner_follow_list.dart @@ -105,6 +105,11 @@ class _OwnerFollowListState extends State return FollowItem( item: followList[index], ctr: widget.ctr, + callback: (attr) { + followList[index].attribute = + attr == 0 ? -1 : 0; + followList.refresh(); + }, ); } }, diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index 850e2bd9..f736e488 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -638,7 +638,7 @@ class Utils { required BuildContext context, required dynamic mid, required bool isFollow, - required Function callback, + required ValueChanged? callback, }) async { if (mid == null) { return; @@ -652,9 +652,7 @@ class Utils { ); SmartDialog.showToast(res['status'] ? "关注成功" : res['msg']); if (res['status']) { - callback(1); - // followStatus['attribute'] = 2; - // followStatus.refresh(); + callback?.call(1); } } else { dynamic result = await VideoHttp.hasFollow(mid: mid); @@ -680,20 +678,11 @@ class Utils { isAdd: !isSpecialFollowed, ); if (res['status']) { - // followStatus['special'] = isSpecialFollowed ? 0 : 1; - // List tags = followStatus['tag'] ?? []; - // if (isSpecialFollowed) { - // tags.remove(-10); - // } else { - // tags.add(-10); - // } - // followStatus['tag'] = tags; - // followStatus.refresh(); SmartDialog.showToast('$text成功'); if (isSpecialFollowed) { - callback(1); + callback?.call(1); } else { - callback(2); + callback?.call(2); } } else { SmartDialog.showToast(res['msg']); @@ -733,9 +722,9 @@ class Utils { }, ); if (result == true) { - callback(2); + callback?.call(2); } else if (result == false) { - callback(1); + callback?.call(1); } }, title: const Text( @@ -755,9 +744,7 @@ class Utils { SmartDialog.showToast( res['status'] ? "取消关注成功" : res['msg']); if (res['status']) { - callback(0); - // followStatus['attribute'] = 0; - // followStatus.refresh(); + callback?.call(0); } }, title: const Text( @@ -772,14 +759,6 @@ class Utils { ); } } - - // MemberController _ = Get.put(MemberController(mid: mid), - // tag: mid.toString()); - // await _.getInfo(); - // if (context.mounted) await _.actionRelationMod(context); - // followStatus['attribute'] = _.attribute.value; - // followStatus.refresh(); - // Get.delete(tag: mid.toString()); } static String generateRandomString(int length) {