feat: 动态样式切换

This commit is contained in:
guozhigq
2024-10-20 00:29:31 +08:00
parent 83c9ce55c8
commit 8292f0e15a
5 changed files with 144 additions and 105 deletions

View File

@ -11,6 +11,7 @@ import 'package:pilipala/common/widgets/no_data.dart';
import 'package:pilipala/models/dynamics/result.dart';
import 'package:pilipala/plugin/pl_popup/index.dart';
import 'package:pilipala/utils/feed_back.dart';
import 'package:pilipala/utils/global_data_cache.dart';
import 'package:pilipala/utils/main_stream.dart';
import 'package:pilipala/utils/route_push.dart';
import 'package:pilipala/utils/storage.dart';
@ -90,8 +91,13 @@ class _DynamicsPageState extends State<DynamicsPage>
mainAxisAlignment: MainAxisAlignment.center,
children: [
Obx(() {
if (_dynamicsController.mid.value != -1 &&
_dynamicsController.upInfo.value.uname != null) {
final mid = _dynamicsController.mid.value;
final uname = _dynamicsController.upInfo.value.uname;
if (mid == -1 || uname == null) {
return const SizedBox();
}
return SizedBox(
height: 36,
child: AnimatedSwitcher(
@ -102,20 +108,17 @@ class _DynamicsPageState extends State<DynamicsPage>
scale: animation, child: child);
},
child: Text(
'${_dynamicsController.upInfo.value.uname!}的动态',
key: ValueKey<String>(
_dynamicsController.upInfo.value.uname!),
'$uname的动态',
key: ValueKey<String>(uname),
style: TextStyle(
fontSize: Theme.of(context)
.textTheme
.labelLarge!
.fontSize,
)),
),
),
),
);
} else {
return const SizedBox();
}
}),
Obx(
() => _dynamicsController.userLogin.value
@ -207,14 +210,19 @@ class _DynamicsPageState extends State<DynamicsPage>
() => UpPanel(
upData: _dynamicsController.upData.value,
onClickUpCb: (data) {
// _dynamicsController.onTapUp(data);
if (GlobalDataCache().enableDynamicSwitch) {
Navigator.push(
context,
PlPopupRoute(
child: OverlayPanel(
ctr: _dynamicsController, upInfo: data),
ctr: _dynamicsController,
upInfo: data,
),
),
);
} else {
_dynamicsController.onTapUp(data);
}
},
),
);

View File

@ -5,6 +5,7 @@ import 'package:pilipala/common/widgets/network_img_layer.dart';
import 'package:pilipala/models/dynamics/up.dart';
import 'package:pilipala/models/live/item.dart';
import 'package:pilipala/utils/feed_back.dart';
import 'package:pilipala/utils/global_data_cache.dart';
import 'package:pilipala/utils/utils.dart';
class UpPanel extends StatefulWidget {
@ -23,7 +24,7 @@ class UpPanel extends StatefulWidget {
class _UpPanelState extends State<UpPanel> {
final ScrollController scrollController = ScrollController();
int currentMid = -1;
RxInt currentMid = (-1).obs;
late double contentWidth = 56;
List<UpItem> upList = [];
List<LiveUserItem> liveList = [];
@ -37,26 +38,36 @@ class _UpPanelState extends State<UpPanel> {
}
void onClickUp(data, i) {
currentMid = data.mid;
currentMid.value = data.mid;
widget.onClickUpCb?.call(data);
// int liveLen = liveList.length;
// int upLen = upList.length;
// double itemWidth = contentWidth + itemPadding.horizontal;
// double screenWidth = MediaQuery.sizeOf(context).width;
// double moveDistance = 0.0;
// if (itemWidth * (upList.length + liveList.length) <= screenWidth) {
// } else if ((upLen - i - 0.5) * itemWidth > screenWidth / 2) {
// moveDistance = (i + liveLen + 0.5) * itemWidth + 46 - screenWidth / 2;
// } else {
// moveDistance = (upLen + liveLen) * itemWidth + 46 - screenWidth;
// }
// data.hasUpdate = false;
// scrollController.animateTo(
// moveDistance,
// duration: const Duration(milliseconds: 200),
// curve: Curves.linear,
// );
// setState(() {});
}
void onClickUpAni(data, i) {
final screenWidth = MediaQuery.sizeOf(context).width;
final itemWidth = contentWidth + itemPadding.horizontal;
final liveLen = liveList.length;
final upLen = upList.length;
currentMid.value = data.mid;
widget.onClickUpCb?.call(data);
double moveDistance = 0.0;
final totalItemsWidth = itemWidth * (upLen + liveLen);
if (totalItemsWidth > screenWidth) {
if ((upLen - i - 0.5) * itemWidth > screenWidth / 2) {
moveDistance = (i + liveLen + 0.5) * itemWidth + 46 - screenWidth / 2;
} else {
moveDistance = totalItemsWidth + 46 - screenWidth;
}
}
data.hasUpdate = false;
scrollController.animateTo(
moveDistance,
duration: const Duration(milliseconds: 500),
curve: Curves.easeInOut,
);
}
@override
@ -144,14 +155,17 @@ class _UpPanelState extends State<UpPanel> {
}
Widget upItemBuild(data, i) {
bool isCurrent = currentMid == data.mid || currentMid == -1;
return InkWell(
onTap: () {
feedBack();
if (data.type == 'up') {
EasyThrottle.throttle('follow', const Duration(milliseconds: 300),
() {
if (GlobalDataCache().enableDynamicSwitch) {
onClickUp(data, i);
} else {
onClickUpAni(data, i);
}
});
} else if (data.type == 'live') {
LiveItemModel liveItem = LiveItemModel.fromJson({
@ -177,8 +191,11 @@ class _UpPanelState extends State<UpPanel> {
},
child: Padding(
padding: itemPadding,
child: AnimatedOpacity(
opacity: isCurrent ? 1 : 0.3,
child: Obx(
() => AnimatedOpacity(
opacity: currentMid.value == data.mid || currentMid.value == -1
? 1
: 0.3,
duration: const Duration(milliseconds: 200),
curve: Curves.easeInOut,
child: Column(
@ -222,11 +239,13 @@ class _UpPanelState extends State<UpPanel> {
softWrap: false,
textAlign: TextAlign.center,
style: TextStyle(
color: currentMid == data.mid
color: currentMid.value == data.mid
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.outline,
fontSize:
Theme.of(context).textTheme.labelMedium!.fontSize),
fontSize: Theme.of(context)
.textTheme
.labelMedium!
.fontSize),
),
),
),
@ -234,6 +253,7 @@ class _UpPanelState extends State<UpPanel> {
),
),
),
),
);
}
}

View File

@ -108,6 +108,12 @@ class _StyleSettingState extends State<StyleSetting> {
defaultVal: true,
needReboot: true,
),
const SetSwitchItem(
title: '动态页滑动切换up',
setKey: SettingBoxKey.enableDynamicSwitch,
defaultVal: true,
needReboot: true,
),
ListTile(
onTap: () async {
int? result = await showDialog(

View File

@ -51,6 +51,8 @@ class GlobalDataCache {
late bool enableSearchSuggest = true;
// 简介默认展开
late bool enableAutoExpand = false;
//
late bool enableDynamicSwitch = true;
// 私有构造函数
GlobalDataCache._();
@ -116,5 +118,7 @@ class GlobalDataCache {
setting.get(SettingBoxKey.enableSearchSuggest, defaultValue: true);
enableAutoExpand =
setting.get(SettingBoxKey.enableAutoExpand, defaultValue: false);
enableDynamicSwitch =
setting.get(SettingBoxKey.enableDynamicSwitch, defaultValue: true);
}
}

View File

@ -131,6 +131,7 @@ class SettingBoxKey {
tabbarSort = 'tabbarSort', // 首页tabbar
dynamicBadgeMode = 'dynamicBadgeMode',
enableGradientBg = 'enableGradientBg',
enableDynamicSwitch = 'enableDynamicSwitch',
navBarSort = 'navBarSort',
actionTypeSort = 'actionTypeSort';
}