refa: follow page

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-04-21 20:17:45 +08:00
parent e6e9ce7d57
commit 8b28a31d09
9 changed files with 271 additions and 424 deletions

View File

@@ -1,12 +1,13 @@
import 'package:PiliPlus/common/widgets/loading_widget.dart';
import 'package:PiliPlus/common/widgets/scroll_physics.dart';
import 'package:PiliPlus/http/loading_state.dart';
import 'package:PiliPlus/models/member/tags.dart';
import 'package:PiliPlus/pages/follow/child_view.dart';
import 'package:PiliPlus/utils/utils.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'controller.dart';
import 'widgets/follow_list.dart';
import 'widgets/owner_follow_list.dart';
import 'package:PiliPlus/common/widgets/scroll_physics.dart';
// TODO: refactor
class FollowPage extends StatefulWidget {
const FollowPage({super.key});
@@ -15,112 +16,94 @@ class FollowPage extends StatefulWidget {
}
class _FollowPageState extends State<FollowPage> {
late String mid;
late FollowController _followController;
@override
void initState() {
super.initState();
mid = Get.parameters['mid']!;
_followController =
Get.put(FollowController(), tag: Utils.makeHeroTag(mid));
}
final FollowController _followController =
Get.put(FollowController(), tag: Utils.generateRandomString(8));
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
_followController.isOwner.value
? '我的关注'
: '${_followController.name}的关注',
_followController.isOwner ? '我的关注' : '${_followController.name}的关注',
),
actions: [
IconButton(
onPressed: () => Get.toNamed(
'/followSearch',
arguments: {
'mid': int.parse(mid),
},
),
icon: const Icon(Icons.search_outlined),
tooltip: '搜索',
),
PopupMenuButton(
icon: const Icon(Icons.more_vert),
itemBuilder: (BuildContext context) => <PopupMenuEntry>[
PopupMenuItem(
onTap: () => Get.toNamed('/blackListPage'),
child: const Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.block, size: 19),
SizedBox(width: 10),
Text('黑名单管理'),
actions: _followController.isOwner
? [
IconButton(
onPressed: () => Get.toNamed(
'/followSearch',
arguments: {
'mid': _followController.mid,
},
),
icon: const Icon(Icons.search_outlined),
tooltip: '搜索',
),
PopupMenuButton(
icon: const Icon(Icons.more_vert),
itemBuilder: (context) => [
PopupMenuItem(
onTap: () => Get.toNamed('/blackListPage'),
child: const Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.block, size: 19),
SizedBox(width: 10),
Text('黑名单管理'),
],
),
)
],
),
)
],
),
const SizedBox(width: 6),
],
),
body: Obx(
() => !_followController.isOwner.value
? FollowList(ctr: _followController)
: FutureBuilder(
future: _followController.followUpTags(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
var data = snapshot.data;
if (data['status']) {
return Column(
children: [
SafeArea(
top: false,
bottom: false,
child: TabBar(
controller: _followController.tabController,
isScrollable: true,
tabAlignment: TabAlignment.start,
tabs: [
for (var i in data['data']) ...[
Tab(text: i.name),
]
],
),
),
Expanded(
child: Material(
color: Colors.transparent,
child: tabBarView(
controller: _followController.tabController,
children: [
for (var i = 0;
i <
_followController
.tabController.length;
i++) ...[
OwnerFollowList(
ctr: _followController,
tagItem: _followController.followTags[i],
)
]
],
),
),
),
],
);
} else {
return const SizedBox();
}
} else {
return const SizedBox();
}
},
),
const SizedBox(width: 6),
]
: null,
),
body: _followController.isOwner
? Obx(() => _buildBody(_followController.followState.value))
: FollowChildPage(mid: _followController.mid),
);
}
Widget _buildBody(LoadingState<List<MemberTagItemModel>?> loadingState) {
return switch (loadingState) {
Loading() => loadingWidget,
Success() => loadingState.response?.isNotEmpty == true
? Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SafeArea(
top: false,
bottom: false,
child: TabBar(
isScrollable: true,
tabAlignment: TabAlignment.start,
controller: _followController.tabController,
tabs: loadingState.response!
.map((item) => Tab(text: item.name))
.toList(),
),
),
Expanded(
child: Material(
color: Colors.transparent,
child: tabBarView(
controller: _followController.tabController,
children: loadingState.response!
.map(
(item) => FollowChildPage(
mid: _followController.mid,
tagid: item.tagid,
),
)
.toList(),
),
),
),
],
)
: FollowChildPage(mid: _followController.mid),
Error() => FollowChildPage(mid: _followController.mid),
_ => throw UnimplementedError(),
};
}
}