mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-06-29 13:50:21 +08:00
@@ -1,151 +1,86 @@
|
||||
import 'package:PiliPlus/http/dynamics.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/common/dynamic/dynamics_type.dart';
|
||||
import 'package:PiliPlus/models/dynamics/up.dart';
|
||||
import 'package:PiliPlus/pages/common/common_controller.dart';
|
||||
import 'package:PiliPlus/pages/common/common_data_controller.dart';
|
||||
import 'package:PiliPlus/pages/dynamics_tab/controller.dart';
|
||||
import 'package:PiliPlus/services/account_service.dart';
|
||||
import 'package:PiliPlus/utils/extension/scroll_controller_ext.dart';
|
||||
import 'package:PiliPlus/utils/extension/string_ext.dart';
|
||||
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||
import 'package:flutter/material.dart' show ScrollController, TabController;
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class DynamicsController extends GetxController
|
||||
with GetSingleTickerProviderStateMixin, ScrollOrRefreshMixin, AccountMixin {
|
||||
@override
|
||||
final ScrollController scrollController = ScrollController();
|
||||
late final TabController tabController;
|
||||
class DynamicsController
|
||||
extends CommonDataController<FollowUpModel, FollowUpModel>
|
||||
with AccountMixin {
|
||||
String? offset;
|
||||
|
||||
late final RxInt mid = (-1).obs;
|
||||
late int currentMid = -1;
|
||||
|
||||
Set<int> tempBannedList = <int>{};
|
||||
|
||||
final Rx<LoadingState<FollowUpModel>> upState =
|
||||
LoadingState<FollowUpModel>.loading().obs;
|
||||
late bool _upEnd = false;
|
||||
bool isEnd = false;
|
||||
late bool showLiveUp = false;
|
||||
|
||||
final Set<int> tempBannedList = <int>{};
|
||||
final upPanelPosition = Pref.upPanelPosition;
|
||||
|
||||
late final innerController = Get.find<DynamicsTabController>();
|
||||
|
||||
@override
|
||||
final AccountService accountService = Get.find<AccountService>();
|
||||
|
||||
DynamicsTabController? get controller {
|
||||
try {
|
||||
return Get.find<DynamicsTabController>(
|
||||
tag: DynamicsTabType.values[tabController.index].name,
|
||||
);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
tabController = TabController(
|
||||
length: DynamicsTabType.values.length,
|
||||
vsync: this,
|
||||
);
|
||||
queryFollowUp();
|
||||
queryData();
|
||||
}
|
||||
|
||||
void onLoadMoreUp() {
|
||||
queryUpList();
|
||||
@override
|
||||
bool customHandleResponse(bool isRefresh, Success<FollowUpModel> response) {
|
||||
final res = response.response;
|
||||
offset = res.offset;
|
||||
if (!isRefresh) {
|
||||
final lastData = loadingState.value.data;
|
||||
if (res.upList case final upList?) {
|
||||
lastData.upList!.addAll(upList);
|
||||
}
|
||||
res
|
||||
..liveUsers = lastData.liveUsers
|
||||
..upList = lastData.upList;
|
||||
}
|
||||
if (res.hasMore != true || offset.isNullOrEmpty) {
|
||||
isEnd = true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<void> queryUpList() async {
|
||||
if (isQuerying || _upEnd) return;
|
||||
isQuerying = true;
|
||||
|
||||
final res = await DynamicsHttp.dynUpList(upState.value.data.offset);
|
||||
|
||||
if (res case Success(:final response)) {
|
||||
if (response.hasMore == false || response.offset.isNullOrEmpty) {
|
||||
_upEnd = true;
|
||||
}
|
||||
final upData = upState.value.data
|
||||
..hasMore = response.hasMore
|
||||
..offset = response.offset;
|
||||
final list = response.upList;
|
||||
if (list != null && list.isNotEmpty) {
|
||||
upData.upList.addAll(list);
|
||||
upState.refresh();
|
||||
}
|
||||
@override
|
||||
Future<LoadingState<FollowUpModel>> customGetData() {
|
||||
if (offset == null) {
|
||||
return DynamicsHttp.followUp();
|
||||
}
|
||||
|
||||
isQuerying = false;
|
||||
return DynamicsHttp.dynUpList(offset);
|
||||
}
|
||||
|
||||
late bool isQuerying = false;
|
||||
Future<void> queryFollowUp() async {
|
||||
if (isQuerying) return;
|
||||
isQuerying = true;
|
||||
|
||||
if (!accountService.isLogin.value) {
|
||||
upState.value = const Error(null);
|
||||
isQuerying = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// reset
|
||||
_upEnd = false;
|
||||
|
||||
final res = await DynamicsHttp.followUp();
|
||||
|
||||
if (res case final Success<FollowUpModel> i) {
|
||||
final data = i.response;
|
||||
if (data.hasMore == false || data.offset.isNullOrEmpty) {
|
||||
_upEnd = true;
|
||||
}
|
||||
upState.value = Success(data);
|
||||
} else {
|
||||
upState.value = const Error(null);
|
||||
}
|
||||
|
||||
isQuerying = false;
|
||||
}
|
||||
|
||||
void onSelectUp(int mid) {
|
||||
if (this.mid.value == mid) {
|
||||
tabController.index = (mid == -1 ? 0 : 4);
|
||||
if (mid == -1) {
|
||||
queryFollowUp();
|
||||
}
|
||||
controller?.onReload();
|
||||
return;
|
||||
}
|
||||
|
||||
this.mid.value = mid;
|
||||
tabController.index = (mid == -1 ? 0 : 4);
|
||||
Future<void> singleRefresh() {
|
||||
offset = null;
|
||||
isEnd = false;
|
||||
return super.onRefresh();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onRefresh() {
|
||||
_refreshFollowUp();
|
||||
return controller!.onRefresh();
|
||||
singleRefresh();
|
||||
return innerController.onRefresh();
|
||||
}
|
||||
|
||||
void _refreshFollowUp() {
|
||||
queryFollowUp();
|
||||
@override
|
||||
Future<void> queryData([bool isRefresh = true]) {
|
||||
if (!isRefresh && isEnd) return Future.value();
|
||||
return super.queryData(isRefresh);
|
||||
}
|
||||
|
||||
@override
|
||||
void animateToTop() {
|
||||
controller?.animateToTop();
|
||||
scrollController.animToTop();
|
||||
super.animateToTop();
|
||||
innerController.scrollController.animToTop();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
mid.close();
|
||||
tabController.dispose();
|
||||
scrollController.dispose();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
@override
|
||||
void onChangeAccount(bool isLogin) => _refreshFollowUp();
|
||||
void onChangeAccount(bool isLogin) => onReload();
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import 'package:PiliPlus/common/widgets/scroll_physics.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/common/dynamic/dynamics_type.dart';
|
||||
import 'package:PiliPlus/models/common/dynamic/up_panel_position.dart';
|
||||
import 'package:PiliPlus/models/dynamics/up.dart';
|
||||
import 'package:PiliPlus/pages/dynamics/controller.dart';
|
||||
import 'package:PiliPlus/pages/dynamics/widgets/up_panel.dart';
|
||||
import 'package:PiliPlus/pages/dynamics_create/view.dart';
|
||||
import 'package:PiliPlus/pages/dynamics_tab/controller.dart';
|
||||
import 'package:PiliPlus/pages/dynamics_tab/view.dart';
|
||||
import 'package:PiliPlus/utils/extension/get_ext.dart';
|
||||
import 'package:flutter/material.dart' hide DraggableScrollableSheet;
|
||||
import 'package:get/get.dart';
|
||||
|
||||
@@ -20,52 +18,59 @@ class DynamicsPage extends StatefulWidget {
|
||||
|
||||
class _DynamicsPageState extends State<DynamicsPage>
|
||||
with AutomaticKeepAliveClientMixin {
|
||||
final _dynamicsController = Get.putOrFind(DynamicsController.new);
|
||||
UpPanelPosition get upPanelPosition => _dynamicsController.upPanelPosition;
|
||||
late ColorScheme colorScheme;
|
||||
late final DynamicsController _outerController;
|
||||
late final DynamicsTabController _innerController;
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
void initState() {
|
||||
super.initState();
|
||||
_outerController = Get.put(DynamicsController());
|
||||
_innerController = Get.put(DynamicsTabController());
|
||||
}
|
||||
|
||||
Widget _createDynamicBtn(ThemeData theme, {bool isRight = true}) => Center(
|
||||
child: Container(
|
||||
width: 34,
|
||||
height: 34,
|
||||
margin: EdgeInsets.only(left: !isRight ? 16 : 0, right: isRight ? 16 : 0),
|
||||
child: IconButton(
|
||||
tooltip: '发布动态',
|
||||
style: ButtonStyle(
|
||||
padding: const WidgetStatePropertyAll(EdgeInsets.zero),
|
||||
backgroundColor: WidgetStatePropertyAll(
|
||||
theme.colorScheme.secondaryContainer,
|
||||
),
|
||||
),
|
||||
onPressed: () => CreateDynPanel.onCreateDyn(context),
|
||||
icon: Icon(
|
||||
Icons.add,
|
||||
size: 18,
|
||||
color: theme.colorScheme.onSecondaryContainer,
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
colorScheme = ColorScheme.of(context);
|
||||
}
|
||||
|
||||
Widget _createDynamicBtn() => SizedBox(
|
||||
width: 34,
|
||||
height: 34,
|
||||
child: IconButton(
|
||||
tooltip: '发布动态',
|
||||
style: ButtonStyle(
|
||||
padding: const WidgetStatePropertyAll(.zero),
|
||||
backgroundColor: WidgetStatePropertyAll(
|
||||
colorScheme.secondaryContainer,
|
||||
),
|
||||
),
|
||||
onPressed: () => CreateDynPanel.onCreateDyn(context),
|
||||
icon: Icon(
|
||||
Icons.add,
|
||||
size: 18,
|
||||
color: colorScheme.onSecondaryContainer,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Widget upPanelPart(ThemeData theme, {bool isTop = false}) {
|
||||
final needBg = upPanelPosition.index > 2;
|
||||
Widget upPanelPart({bool isTop = false}) {
|
||||
return Material(
|
||||
type: needBg ? .canvas : .transparency,
|
||||
color: needBg ? theme.colorScheme.surface : null,
|
||||
type: .transparency,
|
||||
child: SizedBox(
|
||||
width: isTop ? null : 64,
|
||||
height: isTop ? 76 : null,
|
||||
child: NotificationListener<ScrollEndNotification>(
|
||||
onNotification: (notification) {
|
||||
final metrics = notification.metrics;
|
||||
if (metrics.pixels >= metrics.maxScrollExtent - 300) {
|
||||
_dynamicsController.onLoadMoreUp();
|
||||
if (metrics.pixels >= metrics.maxScrollExtent - 300 &&
|
||||
!_outerController.isEnd) {
|
||||
_outerController.onLoadMore();
|
||||
}
|
||||
return false;
|
||||
},
|
||||
child: Obx(() => _buildUpPanel(_dynamicsController.upState.value)),
|
||||
child: Obx(() => _buildUpPanel(_outerController.loadingState.value)),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -74,15 +79,14 @@ class _DynamicsPageState extends State<DynamicsPage>
|
||||
Widget _buildUpPanel(LoadingState<FollowUpModel> upState) {
|
||||
return switch (upState) {
|
||||
Loading() => const SizedBox.shrink(),
|
||||
Success<FollowUpModel>() => UpPanel(
|
||||
dynamicsController: _dynamicsController,
|
||||
Success<FollowUpModel>(:final response) => UpPanel(
|
||||
controller: _outerController,
|
||||
upData: response,
|
||||
),
|
||||
Error() => Center(
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.refresh),
|
||||
onPressed: () => _dynamicsController
|
||||
..upState.value = LoadingState<FollowUpModel>.loading()
|
||||
..queryFollowUp(),
|
||||
onPressed: _outerController.onReload,
|
||||
),
|
||||
),
|
||||
};
|
||||
@@ -91,79 +95,107 @@ class _DynamicsPageState extends State<DynamicsPage>
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
final theme = Theme.of(context);
|
||||
|
||||
Widget? leading;
|
||||
List<Widget>? actions;
|
||||
final tab = _buildTab();
|
||||
Widget child = DynamicsTabPage(controller: _innerController);
|
||||
|
||||
Widget child = tabBarView(
|
||||
controller: _dynamicsController.tabController,
|
||||
children: DynamicsTabType.values
|
||||
.map((e) => DynamicsTabPage(dynamicsType: e))
|
||||
.toList(),
|
||||
);
|
||||
|
||||
switch (upPanelPosition) {
|
||||
switch (_outerController.upPanelPosition) {
|
||||
case .top:
|
||||
child = Column(
|
||||
return Column(
|
||||
children: [
|
||||
upPanelPart(theme, isTop: true),
|
||||
tab,
|
||||
upPanelPart(isTop: true),
|
||||
Expanded(child: child),
|
||||
],
|
||||
);
|
||||
actions = [_createDynamicBtn(theme)];
|
||||
case .leftFixed:
|
||||
child = Row(
|
||||
children: [
|
||||
upPanelPart(theme),
|
||||
upPanelPart(),
|
||||
Expanded(child: child),
|
||||
],
|
||||
);
|
||||
actions = [_createDynamicBtn(theme)];
|
||||
case .rightFixed:
|
||||
child = Row(
|
||||
children: [
|
||||
Expanded(child: child),
|
||||
upPanelPart(theme),
|
||||
upPanelPart(),
|
||||
],
|
||||
);
|
||||
actions = [_createDynamicBtn(theme)];
|
||||
}
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
AppBar(
|
||||
primary: false,
|
||||
leading: leading,
|
||||
leadingWidth: 50,
|
||||
toolbarHeight: 50,
|
||||
backgroundColor: Colors.transparent,
|
||||
title: SizedBox(
|
||||
height: 50,
|
||||
child: TabBar(
|
||||
dividerHeight: 0,
|
||||
isScrollable: true,
|
||||
tabAlignment: .center,
|
||||
dividerColor: Colors.transparent,
|
||||
labelColor: theme.colorScheme.primary,
|
||||
indicatorColor: theme.colorScheme.primary,
|
||||
controller: _dynamicsController.tabController,
|
||||
unselectedLabelColor: theme.colorScheme.onSurface,
|
||||
labelStyle: const TextStyle(fontSize: 13),
|
||||
tabs: DynamicsTabType.values
|
||||
.map((e) => Tab(text: e.label))
|
||||
.toList(),
|
||||
onTap: (index) {
|
||||
if (!_dynamicsController.tabController.indexIsChanging) {
|
||||
_dynamicsController.animateToTop();
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
actions: actions,
|
||||
),
|
||||
tab,
|
||||
Expanded(child: child),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTab() {
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Obx(
|
||||
() {
|
||||
final dynamicsType = _innerController.dynamicsType.value;
|
||||
return Row(
|
||||
children: DynamicsTabType.values.map((e) {
|
||||
final isCurr = e == dynamicsType;
|
||||
return InkWell(
|
||||
onTap: e == .up && !isCurr
|
||||
? null
|
||||
: () {
|
||||
if (isCurr) {
|
||||
_outerController.animateToTop();
|
||||
return;
|
||||
}
|
||||
if (dynamicsType == .up) {
|
||||
_innerController.hostMid = -1;
|
||||
_outerController.loadingState.refresh();
|
||||
}
|
||||
_innerController
|
||||
..dynamicsType.value = e
|
||||
..onReload();
|
||||
},
|
||||
child: DecoratedBox(
|
||||
decoration: isCurr
|
||||
? BoxDecoration(
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
width: 2.0,
|
||||
color: colorScheme.primary,
|
||||
),
|
||||
),
|
||||
)
|
||||
: const BoxDecoration(),
|
||||
child: Container(
|
||||
height: 46,
|
||||
alignment: .center,
|
||||
padding: const .symmetric(horizontal: 16),
|
||||
child: Text(
|
||||
e.label,
|
||||
style: isCurr
|
||||
? TextStyle(
|
||||
fontSize: 13,
|
||||
color: colorScheme.primary,
|
||||
)
|
||||
: const TextStyle(fontSize: 13),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
_createDynamicBtn(),
|
||||
const SizedBox(width: 16),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
}
|
||||
|
||||
@@ -10,65 +10,181 @@ import 'package:PiliPlus/utils/platform_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class UpPanel extends StatefulWidget {
|
||||
class UpPanel extends StatelessWidget {
|
||||
const UpPanel({
|
||||
required this.dynamicsController,
|
||||
super.key,
|
||||
required this.upData,
|
||||
required this.controller,
|
||||
});
|
||||
|
||||
final DynamicsController dynamicsController;
|
||||
|
||||
@override
|
||||
State<UpPanel> createState() => _UpPanelState();
|
||||
}
|
||||
|
||||
class _UpPanelState extends State<UpPanel> {
|
||||
late final controller = widget.dynamicsController;
|
||||
late final isTop = controller.upPanelPosition == .top;
|
||||
|
||||
void toFollowPage() => Get.to(const LiveFollowPage());
|
||||
final FollowUpModel upData;
|
||||
final DynamicsController controller;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final accountService = controller.accountService;
|
||||
if (!accountService.isLogin.value) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
final theme = Theme.of(context);
|
||||
final upData = controller.upState.value.data;
|
||||
final List<UpItem> upList = upData.upList;
|
||||
final List<LiveUserItem>? liveList = upData.liveUsers?.items;
|
||||
final upList = upData.upList;
|
||||
final liveList = upData.liveUsers?.items;
|
||||
|
||||
final isTop = controller.upPanelPosition == .top;
|
||||
void toFollowPage() => Get.to(const LiveFollowPage());
|
||||
|
||||
Widget buildItem(UpItem item) {
|
||||
final hostMid = controller.innerController.hostMid;
|
||||
final isLive = item is LiveUserItem;
|
||||
final isCurrent = isLive || hostMid == -1 || hostMid == item.mid;
|
||||
|
||||
final isAll = item.mid == -1;
|
||||
void toMemberPage() => Get.toNamed('/member?mid=${item.mid}');
|
||||
|
||||
Widget avatar;
|
||||
if (isAll) {
|
||||
avatar = DecoratedBox(
|
||||
decoration: const BoxDecoration(
|
||||
shape: .circle,
|
||||
color: Color(0xFF5CB67B),
|
||||
),
|
||||
child: Image.asset(
|
||||
width: 38,
|
||||
height: 38,
|
||||
cacheWidth: 38.cacheSize,
|
||||
Assets.logo2,
|
||||
color: Colors.white,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
avatar = Padding(
|
||||
padding: const .symmetric(horizontal: 4),
|
||||
child: NetworkImgLayer(
|
||||
width: 38,
|
||||
height: 38,
|
||||
src: item.face,
|
||||
type: .avatar,
|
||||
),
|
||||
);
|
||||
if (isLive) {
|
||||
avatar = Stack(
|
||||
clipBehavior: .none,
|
||||
children: [
|
||||
avatar,
|
||||
Positioned(
|
||||
top: isLive && !isTop ? -5 : 0,
|
||||
right: -6,
|
||||
child: Badge(
|
||||
label: const Text(' Live '),
|
||||
textColor: theme.colorScheme.onSecondaryContainer,
|
||||
backgroundColor: theme.colorScheme.secondaryContainer
|
||||
.withValues(alpha: 0.75),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
} else if (item.hasUpdate ?? false) {
|
||||
avatar = Stack(
|
||||
clipBehavior: .none,
|
||||
children: [
|
||||
avatar,
|
||||
Positioned(
|
||||
top: 0,
|
||||
right: 4,
|
||||
child: Badge(
|
||||
smallSize: 8,
|
||||
backgroundColor: theme.colorScheme.primary,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return SizedBox(
|
||||
height: 76,
|
||||
width: isTop ? 70 : null,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
if (isLive) {
|
||||
PageUtils.toLiveRoom(item.roomId);
|
||||
} else {
|
||||
if (isAll) {
|
||||
if (hostMid == -1) {
|
||||
controller.singleRefresh();
|
||||
}
|
||||
controller.innerController.dynamicsType.value = .all;
|
||||
} else {
|
||||
item.hasUpdate = false;
|
||||
controller.innerController.dynamicsType.value = .up;
|
||||
}
|
||||
controller.innerController
|
||||
..hostMid = item.mid
|
||||
..onReload();
|
||||
(context as Element).markNeedsBuild();
|
||||
}
|
||||
},
|
||||
// onDoubleTap: isLive ? () => _onSelect(data) : null,
|
||||
onLongPress: !isAll ? toMemberPage : null,
|
||||
onSecondaryTap: !isAll && !PlatformUtils.isMobile
|
||||
? toMemberPage
|
||||
: null,
|
||||
child: Opacity(
|
||||
opacity: isCurrent ? 1 : 0.6,
|
||||
child: Column(
|
||||
spacing: 4,
|
||||
mainAxisSize: .min,
|
||||
mainAxisAlignment: .center,
|
||||
children: [
|
||||
avatar,
|
||||
Padding(
|
||||
padding: const .symmetric(horizontal: 4),
|
||||
child: Text(
|
||||
isTop ? '${item.uname}\n' : item.uname!,
|
||||
maxLines: 2,
|
||||
textAlign: .center,
|
||||
style: TextStyle(
|
||||
color: hostMid == item.mid
|
||||
? theme.colorScheme.primary
|
||||
: theme.colorScheme.outline,
|
||||
height: 1.1,
|
||||
fontSize: 12.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return CustomScrollView(
|
||||
scrollDirection: isTop ? Axis.horizontal : Axis.vertical,
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
controller: controller.scrollController,
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
scrollDirection: isTop ? .horizontal : .vertical,
|
||||
slivers: [
|
||||
SliverToBoxAdapter(
|
||||
child: InkWell(
|
||||
onTap: () => setState(() {
|
||||
onTap: () {
|
||||
controller.showLiveUp = !controller.showLiveUp;
|
||||
}),
|
||||
(context as Element).markNeedsBuild();
|
||||
},
|
||||
onLongPress: toFollowPage,
|
||||
onSecondaryTap: PlatformUtils.isMobile ? null : toFollowPage,
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
alignment: .center,
|
||||
height: isTop ? 76 : 60,
|
||||
padding: isTop ? const EdgeInsets.only(left: 12, right: 6) : null,
|
||||
padding: isTop ? const .only(left: 12, right: 6) : null,
|
||||
child: Text.rich(
|
||||
textAlign: TextAlign.center,
|
||||
textAlign: .center,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
TextSpan(
|
||||
children: [
|
||||
TextSpan(
|
||||
text: 'Live(${upData.liveUsers?.count ?? 0})',
|
||||
),
|
||||
TextSpan(text: 'Live(${upData.liveUsers?.count ?? 0})'),
|
||||
if (!isTop) ...[
|
||||
const TextSpan(text: '\n'),
|
||||
WidgetSpan(
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
alignment: .middle,
|
||||
child: Icon(
|
||||
controller.showLiveUp
|
||||
? Icons.expand_less
|
||||
@@ -79,7 +195,7 @@ class _UpPanelState extends State<UpPanel> {
|
||||
),
|
||||
] else
|
||||
WidgetSpan(
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
alignment: .middle,
|
||||
child: Icon(
|
||||
controller.showLiveUp
|
||||
? Icons.keyboard_arrow_right
|
||||
@@ -98,157 +214,32 @@ class _UpPanelState extends State<UpPanel> {
|
||||
SliverList.builder(
|
||||
itemCount: liveList.length,
|
||||
itemBuilder: (context, index) {
|
||||
return upItemBuild(theme, liveList[index]);
|
||||
return buildItem(liveList[index]);
|
||||
},
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: upItemBuild(theme, UpItem(face: '', uname: '全部动态', mid: -1)),
|
||||
child: buildItem(UpItem(face: '', uname: '全部动态', mid: -1)),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: Obx(
|
||||
() => upItemBuild(
|
||||
theme,
|
||||
() => buildItem(
|
||||
UpItem(
|
||||
uname: '我',
|
||||
face: accountService.face.value,
|
||||
face: controller.accountService.face.value,
|
||||
mid: Accounts.main.mid,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (upList.isNotEmpty)
|
||||
if (upList != null && upList.isNotEmpty)
|
||||
SliverList.builder(
|
||||
itemCount: upList.length,
|
||||
itemBuilder: (context, index) {
|
||||
return upItemBuild(theme, upList[index]);
|
||||
return buildItem(upList[index]);
|
||||
},
|
||||
),
|
||||
if (!isTop) const SliverToBoxAdapter(child: SizedBox(height: 200)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void _onSelect(UpItem data) {
|
||||
controller
|
||||
..currentMid = data.mid
|
||||
..onSelectUp(data.mid);
|
||||
|
||||
data.hasUpdate = false;
|
||||
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
Widget upItemBuild(ThemeData theme, UpItem data) {
|
||||
final currentMid = controller.currentMid;
|
||||
final isLive = data is LiveUserItem;
|
||||
final isCurrent = isLive || currentMid == data.mid || currentMid == -1;
|
||||
|
||||
final isAll = data.mid == -1;
|
||||
void toMemberPage() => Get.toNamed('/member?mid=${data.mid}');
|
||||
|
||||
Widget avatar;
|
||||
if (isAll) {
|
||||
avatar = DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
shape: .circle,
|
||||
border: Border.all(
|
||||
width: 5,
|
||||
color: const Color(0xFF5CB67B),
|
||||
),
|
||||
),
|
||||
child: Image.asset(
|
||||
width: 38,
|
||||
height: 38,
|
||||
cacheWidth: 38.cacheSize,
|
||||
Assets.logo,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
avatar = Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4),
|
||||
child: NetworkImgLayer(
|
||||
width: 38,
|
||||
height: 38,
|
||||
src: data.face,
|
||||
type: .avatar,
|
||||
),
|
||||
);
|
||||
if (isLive) {
|
||||
avatar = Stack(
|
||||
clipBehavior: .none,
|
||||
children: [
|
||||
avatar,
|
||||
Positioned(
|
||||
top: isLive && !isTop ? -5 : 0,
|
||||
right: -6,
|
||||
child: Badge(
|
||||
label: const Text(' Live '),
|
||||
textColor: theme.colorScheme.onSecondaryContainer,
|
||||
backgroundColor: theme.colorScheme.secondaryContainer
|
||||
.withValues(alpha: 0.75),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
} else if (data.hasUpdate ?? false) {
|
||||
avatar = Stack(
|
||||
clipBehavior: .none,
|
||||
children: [
|
||||
avatar,
|
||||
Positioned(
|
||||
top: 0,
|
||||
right: 4,
|
||||
child: Badge(
|
||||
smallSize: 8,
|
||||
backgroundColor: theme.colorScheme.primary,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return SizedBox(
|
||||
height: 76,
|
||||
width: isTop ? 70 : null,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
if (isLive) {
|
||||
PageUtils.toLiveRoom(data.roomId);
|
||||
} else {
|
||||
_onSelect(data);
|
||||
}
|
||||
},
|
||||
// onDoubleTap: isLive ? () => _onSelect(data) : null,
|
||||
onLongPress: !isAll ? toMemberPage : null,
|
||||
onSecondaryTap: !isAll && !PlatformUtils.isMobile ? toMemberPage : null,
|
||||
child: Opacity(
|
||||
opacity: isCurrent ? 1 : 0.6,
|
||||
child: Column(
|
||||
spacing: 4,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
avatar,
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4),
|
||||
child: Text(
|
||||
isTop ? '${data.uname}\n' : data.uname!,
|
||||
maxLines: 2,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: currentMid == data.mid
|
||||
? theme.colorScheme.primary
|
||||
: theme.colorScheme.outline,
|
||||
height: 1.1,
|
||||
fontSize: 12.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user