fix: zoneController error

This commit is contained in:
guozhigq
2024-04-16 00:11:36 +08:00
parent 1c692a7ba0
commit 0b8d329ec8
4 changed files with 18 additions and 30 deletions

View File

@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:pilipala/pages/rank/zone/index.dart';
enum RandType {
@ -74,7 +73,6 @@ List tabsConfig = [
),
'label': '全站',
'type': RandType.all,
'ctr': Get.put<ZoneController>,
'page': const ZonePage(rid: 0),
},
{
@ -84,7 +82,6 @@ List tabsConfig = [
),
'label': '国创相关',
'type': RandType.creation,
'ctr': Get.put<ZoneController>,
'page': const ZonePage(rid: 168),
},
{
@ -94,7 +91,6 @@ List tabsConfig = [
),
'label': '动画',
'type': RandType.animation,
'ctr': Get.put<ZoneController>,
'page': const ZonePage(rid: 1),
},
{
@ -104,7 +100,6 @@ List tabsConfig = [
),
'label': '音乐',
'type': RandType.music,
'ctr': Get.put<ZoneController>,
'page': const ZonePage(rid: 3),
},
{
@ -114,7 +109,6 @@ List tabsConfig = [
),
'label': '舞蹈',
'type': RandType.dance,
'ctr': Get.put<ZoneController>,
'page': const ZonePage(rid: 129),
},
{
@ -124,7 +118,6 @@ List tabsConfig = [
),
'label': '游戏',
'type': RandType.game,
'ctr': Get.put<ZoneController>,
'page': const ZonePage(rid: 4),
},
{
@ -134,7 +127,6 @@ List tabsConfig = [
),
'label': '知识',
'type': RandType.knowledge,
'ctr': Get.put<ZoneController>,
'page': const ZonePage(rid: 36),
},
{
@ -144,7 +136,6 @@ List tabsConfig = [
),
'label': '科技',
'type': RandType.technology,
'ctr': Get.put<ZoneController>,
'page': const ZonePage(rid: 188),
},
{
@ -154,7 +145,6 @@ List tabsConfig = [
),
'label': '运动',
'type': RandType.sport,
'ctr': Get.put<ZoneController>,
'page': const ZonePage(rid: 234),
},
{
@ -164,7 +154,6 @@ List tabsConfig = [
),
'label': '汽车',
'type': RandType.car,
'ctr': Get.put<ZoneController>,
'page': const ZonePage(rid: 223),
},
{
@ -174,7 +163,6 @@ List tabsConfig = [
),
'label': '生活',
'type': RandType.life,
'ctr': Get.put<ZoneController>,
'page': const ZonePage(rid: 160),
},
{
@ -184,7 +172,6 @@ List tabsConfig = [
),
'label': '美食',
'type': RandType.food,
'ctr': Get.put<ZoneController>,
'page': const ZonePage(rid: 211),
},
{
@ -194,7 +181,6 @@ List tabsConfig = [
),
'label': '动物圈',
'type': RandType.animal,
'ctr': Get.put<ZoneController>,
'page': const ZonePage(rid: 217),
},
{
@ -204,7 +190,6 @@ List tabsConfig = [
),
'label': '鬼畜',
'type': RandType.madness,
'ctr': Get.put<ZoneController>,
'page': const ZonePage(rid: 119),
},
{
@ -214,7 +199,6 @@ List tabsConfig = [
),
'label': '时尚',
'type': RandType.fashion,
'ctr': Get.put<ZoneController>,
'page': const ZonePage(rid: 155),
},
{
@ -224,7 +208,6 @@ List tabsConfig = [
),
'label': '娱乐',
'type': RandType.entertainment,
'ctr': Get.put<ZoneController>,
'page': const ZonePage(rid: 5),
},
{
@ -234,7 +217,6 @@ List tabsConfig = [
),
'label': '影视',
'type': RandType.film,
'ctr': Get.put<ZoneController>,
'page': const ZonePage(rid: 181),
}
];

View File

@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hive/hive.dart';
import 'package:pilipala/models/common/rank_type.dart';
import 'package:pilipala/pages/rank/zone/index.dart';
import 'package:pilipala/utils/storage.dart';
class RankController extends GetxController with GetTickerProviderStateMixin {
@ -29,20 +30,22 @@ class RankController extends GetxController with GetTickerProviderStateMixin {
void onRefresh() {
int index = tabController.index;
var ctr = tabsCtrList[index];
ctr().onRefresh();
final ZoneController ctr = tabsCtrList[index];
ctr.onRefresh();
}
void animateToTop() {
int index = tabController.index;
var ctr = tabsCtrList[index];
ctr().animateToTop();
final ZoneController ctr = tabsCtrList[index];
ctr.animateToTop();
}
void setTabConfig() async {
tabs.value = tabsConfig;
initialIndex.value = 0;
tabsCtrList = tabs.map((e) => e['ctr']).toList();
tabsCtrList = tabs
.map((e) => Get.put(ZoneController(), tag: e['rid'].toString()))
.toList();
tabsPageList = tabs.map<Widget>((e) => e['page']).toList();
tabController = TabController(

View File

@ -102,7 +102,7 @@ class _RankPageState extends State<RankPage>
onTap: (value) {
feedBack();
if (_rankController.initialIndex.value == value) {
_rankController.tabsCtrList[value]().animateToTop();
_rankController.tabsCtrList[value].animateToTop();
}
_rankController.initialIndex.value = value;
},

View File

@ -42,12 +42,15 @@ class ZoneController extends GetxController {
// 返回顶部并刷新
void animateToTop() async {
if (scrollController.offset >=
MediaQuery.of(Get.context!).size.height * 5) {
scrollController.jumpTo(0);
} else {
await scrollController.animateTo(0,
duration: const Duration(milliseconds: 500), curve: Curves.easeInOut);
if (scrollController.hasClients) {
if (scrollController.offset >=
MediaQuery.of(Get.context!).size.height * 5) {
scrollController.jumpTo(0);
} else {
await scrollController.animateTo(0,
duration: const Duration(milliseconds: 500),
curve: Curves.easeInOut);
}
}
}
}