mod: 点击底栏返回顶部
This commit is contained in:
@ -11,6 +11,7 @@ class HomeController extends GetxController {
|
||||
int crossAxisCount = 2;
|
||||
RxList<RecVideoItemModel> videoList = [RecVideoItemModel()].obs;
|
||||
bool isLoadingMore = false;
|
||||
bool flag = false;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
@ -49,4 +50,15 @@ class HomeController extends GetxController {
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
queryRcmdFeed('onLoad');
|
||||
}
|
||||
|
||||
// 返回顶部并刷新
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
// import 'package:pilipala/pages/home/controller.dart';
|
||||
import 'package:pilipala/pages/home/index.dart';
|
||||
import './controller.dart';
|
||||
|
||||
class MainApp extends StatefulWidget {
|
||||
@ -11,10 +13,13 @@ class MainApp extends StatefulWidget {
|
||||
|
||||
class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
|
||||
final MainController _mainController = Get.put(MainController());
|
||||
final HomeController _homeController = Get.put(HomeController());
|
||||
|
||||
late AnimationController? _animationController;
|
||||
late Animation<double>? _fadeAnimation;
|
||||
late Animation<double>? _slideAnimation;
|
||||
int selectedIndex = 0;
|
||||
int? _lastSelectTime; //上次点击时间
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -29,9 +34,10 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
|
||||
Tween<double>(begin: 0.8, end: 1.0).animate(_animationController!);
|
||||
_slideAnimation =
|
||||
Tween(begin: 0.8, end: 1.0).animate(_animationController!);
|
||||
_lastSelectTime = DateTime.now().millisecondsSinceEpoch;
|
||||
}
|
||||
|
||||
void setIndex(int value) {
|
||||
void setIndex(int value) async {
|
||||
if (selectedIndex != value) {
|
||||
selectedIndex = value;
|
||||
_animationController!.reverse().then((_) {
|
||||
@ -40,6 +46,23 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
|
||||
});
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
var currentPage = _mainController.pages[value];
|
||||
if (currentPage is HomePage) {
|
||||
if (_homeController.flag) {
|
||||
// 单击返回顶部 双击并刷新
|
||||
if (DateTime.now().millisecondsSinceEpoch - _lastSelectTime! < 500) {
|
||||
_homeController.onRefresh();
|
||||
} else {
|
||||
await Future.delayed(const Duration(microseconds: 300));
|
||||
_homeController.animateToTop();
|
||||
}
|
||||
_lastSelectTime = DateTime.now().millisecondsSinceEpoch;
|
||||
}
|
||||
_homeController.flag = true;
|
||||
} else {
|
||||
_homeController.flag = false;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
Reference in New Issue
Block a user