top up panel

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-05-15 18:48:31 +08:00
parent e54a0f127f
commit 35bc4a6ece
5 changed files with 115 additions and 85 deletions

View File

@@ -1,10 +1,10 @@
enum UpPanelPosition {
leftFixed,
rightFixed,
leftDrawer,
rightDrawer,
}
top('顶部'),
leftFixed('左侧常驻'),
rightFixed('右侧常驻'),
leftDrawer('左侧抽屉'),
rightDrawer('右侧抽屉');
extension UpPanelPositionExt on UpPanelPosition {
String get labels => const ['左侧常驻', '右侧常驻', '左侧抽屉', '右侧抽屉'][index];
final String label;
const UpPanelPosition(this.label);
}

View File

@@ -39,6 +39,8 @@ class DynamicsController extends GetxController
late int currentMid = -1;
late bool showLiveItems = GStorage.expandDynLivePanel;
final upPanelPosition = GStorage.upPanelPosition;
DynamicsTabController? get controller {
try {
return Get.find<DynamicsTabController>(

View File

@@ -19,20 +19,12 @@ class DynamicsPage extends StatefulWidget {
class _DynamicsPageState extends State<DynamicsPage>
with AutomaticKeepAliveClientMixin {
final DynamicsController _dynamicsController = Get.put(DynamicsController());
late UpPanelPosition upPanelPosition;
late ThemeData theme;
@override
void didChangeDependencies() {
super.didChangeDependencies();
theme = Theme.of(context);
}
UpPanelPosition get upPanelPosition => _dynamicsController.upPanelPosition;
@override
bool get wantKeepAlive => true;
Widget _createDynamicBtn([bool isRight = true]) => Center(
Widget _createDynamicBtn(ThemeData theme, [bool isRight = true]) => Center(
child: Container(
width: 34,
height: 34,
@@ -68,8 +60,6 @@ class _DynamicsPageState extends State<DynamicsPage>
@override
void initState() {
super.initState();
upPanelPosition = GStorage.upPanelPosition;
debugPrint('upPanelPosition: $upPanelPosition');
if (GStorage.setting
.get(SettingBoxKey.dynamicsShowAllFollowedUp, defaultValue: false)) {
_dynamicsController.scrollController.addListener(listener);
@@ -91,33 +81,37 @@ class _DynamicsPageState extends State<DynamicsPage>
super.dispose();
}
Widget upPanelPart() {
return Container(
Widget upPanelPart(ThemeData theme) {
bool isTop = upPanelPosition == UpPanelPosition.top;
return Material(
//抽屉模式增加底色
color: upPanelPosition.index > 1
color: isTop || upPanelPosition.index > 1
? theme.colorScheme.surface
: Colors.transparent,
width: 64,
child: Obx(
() {
if (_dynamicsController.upData.value.upList == null &&
_dynamicsController.upData.value.liveUsers == null) {
return const SizedBox.shrink();
} else if (_dynamicsController.upData.value.errMsg != null) {
return Center(
child: IconButton(
icon: const Icon(Icons.refresh),
onPressed: () {
_dynamicsController.queryFollowUp();
},
),
);
} else {
return UpPanel(
dynamicsController: _dynamicsController,
);
}
},
child: SizedBox(
width: isTop ? null : 64,
height: isTop ? 76 : null,
child: Obx(
() {
if (_dynamicsController.upData.value.upList == null &&
_dynamicsController.upData.value.liveUsers == null) {
return const SizedBox.shrink();
} else if (_dynamicsController.upData.value.errMsg != null) {
return Center(
child: IconButton(
icon: const Icon(Icons.refresh),
onPressed: () {
_dynamicsController.queryFollowUp();
},
),
);
} else {
return UpPanel(
dynamicsController: _dynamicsController,
);
}
},
),
),
);
}
@@ -125,11 +119,12 @@ class _DynamicsPageState extends State<DynamicsPage>
@override
Widget build(BuildContext context) {
super.build(context);
ThemeData theme = Theme.of(context);
return Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
leading: upPanelPosition == UpPanelPosition.rightDrawer
? _createDynamicBtn(false)
? _createDynamicBtn(theme, false)
: null,
leadingWidth: 50,
toolbarHeight: 50,
@@ -158,26 +153,33 @@ class _DynamicsPageState extends State<DynamicsPage>
),
actions: upPanelPosition == UpPanelPosition.rightDrawer
? null
: [_createDynamicBtn()],
: [_createDynamicBtn(theme)],
),
drawer: upPanelPosition == UpPanelPosition.leftDrawer
? SafeArea(child: upPanelPart())
? SafeArea(child: upPanelPart(theme))
: null,
drawerEnableOpenDragGesture: true,
endDrawer: upPanelPosition == UpPanelPosition.rightDrawer
? SafeArea(child: upPanelPart())
? SafeArea(child: upPanelPart(theme))
: null,
endDrawerEnableOpenDragGesture: true,
body: Row(
children: [
if (upPanelPosition == UpPanelPosition.leftFixed) upPanelPart(),
if (upPanelPosition == UpPanelPosition.leftFixed) upPanelPart(theme),
Expanded(
child: tabBarView(
controller: _dynamicsController.tabController,
children: _dynamicsController.tabsPageList,
child: Column(
children: [
if (upPanelPosition == UpPanelPosition.top) upPanelPart(theme),
Expanded(
child: tabBarView(
controller: _dynamicsController.tabController,
children: _dynamicsController.tabsPageList,
),
),
],
),
),
if (upPanelPosition == UpPanelPosition.rightFixed) upPanelPart(),
if (upPanelPosition == UpPanelPosition.rightFixed) upPanelPart(theme),
],
),
);

View File

@@ -1,4 +1,5 @@
import 'package:PiliPlus/common/widgets/image/network_img_layer.dart';
import 'package:PiliPlus/models/common/dynamic/up_panel_position.dart';
import 'package:PiliPlus/models/common/image_type.dart';
import 'package:PiliPlus/models/dynamics/up.dart';
import 'package:PiliPlus/pages/dynamics/controller.dart';
@@ -8,11 +9,11 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
class UpPanel extends StatefulWidget {
final DynamicsController dynamicsController;
const UpPanel({
required this.dynamicsController,
super.key,
});
final DynamicsController dynamicsController;
@override
State<UpPanel> createState() => _UpPanelState();
@@ -22,6 +23,8 @@ class _UpPanelState extends State<UpPanel> {
List<UpItem>? get upList => widget.dynamicsController.upData.value.upList;
List<LiveUserItem>? get liveList =>
widget.dynamicsController.upData.value.liveUsers?.items;
late final isTop =
widget.dynamicsController.upPanelPosition == UpPanelPosition.top;
@override
Widget build(BuildContext context) {
@@ -30,41 +33,63 @@ class _UpPanelState extends State<UpPanel> {
return const SizedBox.shrink();
}
return CustomScrollView(
scrollDirection: isTop ? Axis.horizontal : Axis.vertical,
physics: const AlwaysScrollableScrollPhysics(),
controller: widget.dynamicsController.scrollController,
slivers: [
SliverToBoxAdapter(
child: SizedBox(
height: 45,
child: TextButton(
style: TextButton.styleFrom(
padding: EdgeInsets.zero,
child: InkWell(
onTap: () {
setState(() {
widget.dynamicsController.showLiveItems =
!widget.dynamicsController.showLiveItems;
});
},
child: Container(
alignment: Alignment.center,
height: isTop ? 76 : 60,
padding: isTop ? const EdgeInsets.symmetric(horizontal: 6) : null,
child: Text.rich(
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 13,
color: theme.colorScheme.primary,
),
TextSpan(
children: [
TextSpan(
text:
'Live(${widget.dynamicsController.upData.value.liveUsers?.count})',
),
if (!isTop) ...[
const TextSpan(text: '\n'),
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: Icon(
widget.dynamicsController.showLiveItems
? Icons.expand_less
: Icons.expand_more,
size: 12,
color: theme.colorScheme.primary,
),
),
] else
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: Icon(
widget.dynamicsController.showLiveItems
? Icons.keyboard_arrow_right
: Icons.keyboard_arrow_left,
color: theme.colorScheme.primary,
size: 14,
),
),
],
),
),
child: Column(
children: [
const SizedBox(height: 12),
Text(
'Live(${widget.dynamicsController.upData.value.liveUsers?.count})',
style: const TextStyle(fontSize: 13),
),
Icon(
widget.dynamicsController.showLiveItems
? Icons.expand_less
: Icons.expand_more,
size: 12,
),
],
),
onPressed: () {
setState(() {
widget.dynamicsController.showLiveItems =
!widget.dynamicsController.showLiveItems;
});
},
),
),
),
const SliverToBoxAdapter(child: SizedBox(height: 10)),
if (widget.dynamicsController.showLiveItems &&
liveList?.isNotEmpty == true)
SliverList.builder(
@@ -93,7 +118,7 @@ class _UpPanelState extends State<UpPanel> {
return upItemBuild(theme, upList![index]);
},
),
const SliverToBoxAdapter(child: SizedBox(height: 200)),
if (!isTop) const SliverToBoxAdapter(child: SizedBox(height: 200)),
],
);
}
@@ -103,6 +128,7 @@ class _UpPanelState extends State<UpPanel> {
widget.dynamicsController.currentMid == -1;
return SizedBox(
height: 76,
width: isTop ? 65 : null,
child: InkWell(
onTap: () {
feedBack();
@@ -172,13 +198,13 @@ class _UpPanelState extends State<UpPanel> {
),
],
),
const SizedBox(height: 3),
const SizedBox(height: 4),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: Text(
data.uname,
overflow: TextOverflow.clip,
maxLines: 2,
maxLines: isTop ? 1 : 2,
softWrap: true,
textAlign: TextAlign.center,
style: TextStyle(

View File

@@ -283,7 +283,7 @@ List<SettingsModel> get styleSettings => [
settingsType: SettingsType.normal,
title: '动态页UP主显示位置',
leading: const Icon(Icons.person_outlined),
getSubtitle: () => '当前:${GStorage.upPanelPosition.labels}',
getSubtitle: () => '当前:${GStorage.upPanelPosition.label}',
onTap: (setState) async {
UpPanelPosition? result = await showDialog(
context: Get.context!,
@@ -292,7 +292,7 @@ List<SettingsModel> get styleSettings => [
title: '动态页UP主显示位置',
value: GStorage.upPanelPosition,
values: UpPanelPosition.values.map((e) {
return (e, e.labels);
return (e, e.label);
}).toList(),
);
},