diff --git a/lib/pages/follow/widgets/follow_item.dart b/lib/pages/follow/widgets/follow_item.dart index 4aecd3574..469cf9812 100644 --- a/lib/pages/follow/widgets/follow_item.dart +++ b/lib/pages/follow/widgets/follow_item.dart @@ -8,7 +8,7 @@ import 'package:get/get.dart'; class FollowItem extends StatelessWidget { final FollowItemModel item; - final bool? isOwner; + final bool isOwner; final ValueChanged? afterMod; final ValueChanged? onSelect; @@ -16,15 +16,38 @@ class FollowItem extends StatelessWidget { super.key, required this.item, this.afterMod, - this.isOwner, + bool? isOwner, this.onSelect, - }); + }) : isOwner = isOwner ?? false; @override Widget build(BuildContext context) { final colorScheme = ColorScheme.of(context); + Widget? followBtn; + if (isOwner) { + final isFollow = item.attribute != -1; + followBtn = FilledButton.tonal( + onPressed: () => RequestUtils.actionRelationMod( + context: context, + mid: item.mid, + isFollow: isFollow, + afterMod: afterMod, + ), + style: FilledButton.styleFrom( + visualDensity: .compact, + tapTargetSize: .shrinkWrap, + padding: const .symmetric(horizontal: 15), + foregroundColor: isFollow ? colorScheme.outline : null, + backgroundColor: isFollow ? colorScheme.onInverseSurface : null, + ), + child: Text( + '${isFollow ? '已' : ''}关注', + style: const TextStyle(fontSize: 12), + ), + ); + } return Material( - type: MaterialType.transparency, + type: .transparency, child: InkWell( onTap: () { if (onSelect != null) { @@ -42,10 +65,7 @@ class FollowItem extends StatelessWidget { } }, child: Padding( - padding: const EdgeInsets.symmetric( - horizontal: 12, - vertical: 10, - ), + padding: const .symmetric(horizontal: 12, vertical: 10), child: Row( children: [ PendantAvatar( @@ -58,19 +78,19 @@ class FollowItem extends StatelessWidget { Expanded( child: Column( spacing: 3, - crossAxisAlignment: CrossAxisAlignment.start, + crossAxisAlignment: .start, children: [ Text( item.uname!, maxLines: 1, - overflow: TextOverflow.ellipsis, + overflow: .ellipsis, style: const TextStyle(fontSize: 14), ), if (item.sign != null) Text( item.sign!, maxLines: 1, - overflow: TextOverflow.ellipsis, + overflow: .ellipsis, style: TextStyle( fontSize: 13, color: colorScheme.outline, @@ -79,30 +99,7 @@ class FollowItem extends StatelessWidget { ], ), ), - if (isOwner ?? false) - FilledButton.tonal( - onPressed: () => RequestUtils.actionRelationMod( - context: context, - mid: item.mid, - isFollow: item.attribute != -1, - afterMod: afterMod, - ), - style: FilledButton.styleFrom( - visualDensity: .compact, - tapTargetSize: .shrinkWrap, - padding: const .symmetric(horizontal: 15), - foregroundColor: item.attribute == -1 - ? null - : colorScheme.outline, - backgroundColor: item.attribute == -1 - ? null - : colorScheme.onInverseSurface, - ), - child: Text( - '${item.attribute == -1 ? '' : '已'}关注', - style: const TextStyle(fontSize: 12), - ), - ), + ?followBtn, ], ), ),