Skip to content

Commit

Permalink
fix: anim to top
Browse files Browse the repository at this point in the history
  • Loading branch information
bggRGjQaUbCoE committed Aug 30, 2024
1 parent d9eab8d commit ecefc4b
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 69 deletions.
11 changes: 3 additions & 8 deletions lib/pages/bangumi/controller.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:PiliPalaX/utils/extension.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hive/hive.dart';
Expand Down Expand Up @@ -62,13 +63,7 @@ class BangumiController 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);
}
void animateToTop() {
scrollController.animToTop();
}
}
10 changes: 2 additions & 8 deletions lib/pages/dynamics/controller.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// ignore_for_file: avoid_print

import 'package:PiliPalaX/http/follow.dart';
import 'package:PiliPalaX/utils/extension.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
Expand Down Expand Up @@ -314,13 +315,6 @@ class DynamicsController extends GetxController
// 返回顶部并刷新
void animateToTop() async {
tabsConfig[tabController.index]['ctr'].animateToTop();
if (!scrollController.hasClients) return;
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);
}
scrollController.animToTop();
}
}
11 changes: 3 additions & 8 deletions lib/pages/dynamics/tab/controller.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:PiliPalaX/utils/extension.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -64,13 +65,7 @@ class DynamicsTabController 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);
}
void animateToTop() {
scrollController.animToTop();
}
}
11 changes: 3 additions & 8 deletions lib/pages/hot/controller.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:PiliPalaX/utils/extension.dart';
import 'package:get/get.dart';
import 'package:flutter/material.dart';
import 'package:PiliPalaX/http/video.dart';
Expand Down Expand Up @@ -48,13 +49,7 @@ class HotController 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);
}
void animateToTop() {
scrollController.animToTop();
}
}
11 changes: 3 additions & 8 deletions lib/pages/live/controller.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:PiliPalaX/utils/extension.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hive/hive.dart';
Expand Down Expand Up @@ -50,13 +51,7 @@ class LiveController 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);
}
void animateToTop() {
scrollController.animToTop();
}
}
11 changes: 3 additions & 8 deletions lib/pages/rank/zone/controller.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:PiliPalaX/utils/extension.dart';
import 'package:get/get.dart';
import 'package:flutter/material.dart';
import 'package:PiliPalaX/http/video.dart';
Expand Down Expand Up @@ -41,13 +42,7 @@ 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);
}
void animateToTop() {
scrollController.animToTop();
}
}
11 changes: 3 additions & 8 deletions lib/pages/rcmd/controller.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:PiliPalaX/utils/extension.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
Expand Down Expand Up @@ -97,13 +98,7 @@ class RcmdController 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);
}
void animateToTop() {
scrollController.animToTop();
}
}
11 changes: 3 additions & 8 deletions lib/pages/search_panel/controller.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:PiliPalaX/utils/extension.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:PiliPalaX/http/search.dart';
Expand Down Expand Up @@ -42,14 +43,8 @@ class SearchPanelController 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);
}
void animateToTop() {
scrollController.animToTop();
}

void onPushDetail(keyword, resultList) async {
Expand Down
13 changes: 8 additions & 5 deletions lib/utils/extension.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';

extension ImageExtension on num {
int cacheSize(BuildContext context) {
Expand All @@ -8,10 +9,12 @@ extension ImageExtension on num {

extension ScrollControllerExt on ScrollController {
void animToTop() {
animateTo(
0,
duration: const Duration(milliseconds: 500),
curve: Curves.ease,
);
if (!hasClients) return;
if (offset >= MediaQuery.of(Get.context!).size.height * 5) {
jumpTo(0);
} else {
animateTo(0,
duration: const Duration(milliseconds: 500), curve: Curves.easeInOut);
}
}
}

0 comments on commit ecefc4b

Please sign in to comment.