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