mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
feat: refresh on top (#524)
* feat: refresh on top * check ctr client Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me> --------- Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me> Co-authored-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
committed by
GitHub
parent
7a6085e923
commit
a74edd22c1
@@ -1,9 +1,31 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
abstract class CommonController extends GetxController {
|
||||
abstract mixin class ScrollOrRefreshMixin {
|
||||
ScrollController get scrollController;
|
||||
|
||||
void animateToTop() => scrollController.animToTop();
|
||||
|
||||
Future<void> onRefresh();
|
||||
|
||||
FutureOr<void> toTopOrRefresh() {
|
||||
if (scrollController.hasClients) {
|
||||
if (scrollController.position.pixels == 0) {
|
||||
return onRefresh();
|
||||
} else {
|
||||
animateToTop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract class CommonController extends GetxController
|
||||
with ScrollOrRefreshMixin {
|
||||
@override
|
||||
final ScrollController scrollController = ScrollController();
|
||||
|
||||
int currentPage = 1;
|
||||
@@ -57,7 +79,8 @@ abstract class CommonController extends GetxController {
|
||||
isLoading = false;
|
||||
}
|
||||
|
||||
Future onRefresh() async {
|
||||
@override
|
||||
Future<void> onRefresh() async {
|
||||
currentPage = 1;
|
||||
isEnd = false;
|
||||
await queryData();
|
||||
@@ -67,10 +90,6 @@ abstract class CommonController extends GetxController {
|
||||
await queryData(false);
|
||||
}
|
||||
|
||||
void animateToTop() {
|
||||
scrollController.animToTop();
|
||||
}
|
||||
|
||||
Future onReload() async {
|
||||
loadingState.value = LoadingState.loading();
|
||||
await onRefresh();
|
||||
|
||||
Reference in New Issue
Block a user