From 9ec06f7295bc92019cfca6ab784fd371ea44d4f4 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Tue, 28 May 2024 22:58:51 +0800 Subject: [PATCH] =?UTF-8?q?opt:=20=E5=8A=A8=E6=80=81=E9=A1=B5up=E4=B8=BB?= =?UTF-8?q?=E7=82=B9=E5=87=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/dynamics/widgets/up_panel.dart | 54 +++++++++++++----------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/lib/pages/dynamics/widgets/up_panel.dart b/lib/pages/dynamics/widgets/up_panel.dart index fd0ae642..ee522cbb 100644 --- a/lib/pages/dynamics/widgets/up_panel.dart +++ b/lib/pages/dynamics/widgets/up_panel.dart @@ -1,3 +1,4 @@ +import 'package:easy_debounce/easy_throttle.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:pilipala/common/widgets/network_img_layer.dart'; @@ -30,6 +31,31 @@ class _UpPanelState extends State { liveList = widget.upData.liveList!; } + void onClickUp(data, i) { + currentMid = data.mid; + Get.find().mid.value = data.mid; + Get.find().upInfo.value = data; + Get.find().onSelectUp(data.mid); + 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(() {}); + } + @override Widget build(BuildContext context) { listFormat(); @@ -120,30 +146,10 @@ class _UpPanelState extends State { onTap: () { feedBack(); if (data.type == 'up') { - currentMid = data.mid; - Get.find().mid.value = data.mid; - Get.find().upInfo.value = data; - Get.find().onSelectUp(data.mid); - 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: 500), - curve: Curves.easeInOut, - ); - - setState(() {}); + EasyThrottle.throttle('follow', const Duration(milliseconds: 300), + () { + onClickUp(data, i); + }); } else if (data.type == 'live') { LiveItemModel liveItem = LiveItemModel.fromJson({ 'title': data.title,