feat: 优先返回首页
This commit is contained in:
@ -57,6 +57,8 @@ class MainController extends GetxController {
|
|||||||
Box setting = GStrorage.setting;
|
Box setting = GStrorage.setting;
|
||||||
DateTime? _lastPressedAt;
|
DateTime? _lastPressedAt;
|
||||||
late bool hideTabBar;
|
late bool hideTabBar;
|
||||||
|
late PageController pageController;
|
||||||
|
int selectedIndex = 0;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
@ -73,6 +75,9 @@ class MainController extends GetxController {
|
|||||||
const Duration(seconds: 2)) {
|
const Duration(seconds: 2)) {
|
||||||
// 两次点击时间间隔超过2秒,重新记录时间戳
|
// 两次点击时间间隔超过2秒,重新记录时间戳
|
||||||
_lastPressedAt = DateTime.now();
|
_lastPressedAt = DateTime.now();
|
||||||
|
if (selectedIndex != 0) {
|
||||||
|
pageController.jumpTo(0);
|
||||||
|
}
|
||||||
SmartDialog.showToast("再按一次退出Pili");
|
SmartDialog.showToast("再按一次退出Pili");
|
||||||
return; // 不退出应用
|
return; // 不退出应用
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,6 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
|
|||||||
final DynamicsController _dynamicController = Get.put(DynamicsController());
|
final DynamicsController _dynamicController = Get.put(DynamicsController());
|
||||||
final MediaController _mediaController = Get.put(MediaController());
|
final MediaController _mediaController = Get.put(MediaController());
|
||||||
|
|
||||||
PageController? _pageController;
|
|
||||||
int selectedIndex = 0;
|
|
||||||
int? _lastSelectTime; //上次点击时间
|
int? _lastSelectTime; //上次点击时间
|
||||||
Box setting = GStrorage.setting;
|
Box setting = GStrorage.setting;
|
||||||
late bool enableMYBar;
|
late bool enableMYBar;
|
||||||
@ -34,13 +32,14 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_lastSelectTime = DateTime.now().millisecondsSinceEpoch;
|
_lastSelectTime = DateTime.now().millisecondsSinceEpoch;
|
||||||
_pageController = PageController(initialPage: selectedIndex);
|
_mainController.pageController =
|
||||||
|
PageController(initialPage: _mainController.selectedIndex);
|
||||||
enableMYBar = setting.get(SettingBoxKey.enableMYBar, defaultValue: true);
|
enableMYBar = setting.get(SettingBoxKey.enableMYBar, defaultValue: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setIndex(int value) async {
|
void setIndex(int value) async {
|
||||||
feedBack();
|
feedBack();
|
||||||
_pageController!.jumpToPage(value);
|
_mainController.pageController!.jumpToPage(value);
|
||||||
var currentPage = _mainController.pages[value];
|
var currentPage = _mainController.pages[value];
|
||||||
if (currentPage is HomePage) {
|
if (currentPage is HomePage) {
|
||||||
if (_homeController.flag) {
|
if (_homeController.flag) {
|
||||||
@ -102,9 +101,9 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
|
|||||||
extendBody: true,
|
extendBody: true,
|
||||||
body: PageView(
|
body: PageView(
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
controller: _pageController,
|
controller: _mainController.pageController,
|
||||||
onPageChanged: (index) {
|
onPageChanged: (index) {
|
||||||
selectedIndex = index;
|
_mainController.selectedIndex = index;
|
||||||
setState(() {});
|
setState(() {});
|
||||||
},
|
},
|
||||||
children: _mainController.pages,
|
children: _mainController.pages,
|
||||||
@ -122,7 +121,7 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
|
|||||||
child: enableMYBar
|
child: enableMYBar
|
||||||
? NavigationBar(
|
? NavigationBar(
|
||||||
onDestinationSelected: (value) => setIndex(value),
|
onDestinationSelected: (value) => setIndex(value),
|
||||||
selectedIndex: selectedIndex,
|
selectedIndex: _mainController.selectedIndex,
|
||||||
destinations: <Widget>[
|
destinations: <Widget>[
|
||||||
..._mainController.navigationBars.map((e) {
|
..._mainController.navigationBars.map((e) {
|
||||||
return NavigationDestination(
|
return NavigationDestination(
|
||||||
@ -134,7 +133,7 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
: BottomNavigationBar(
|
: BottomNavigationBar(
|
||||||
currentIndex: selectedIndex,
|
currentIndex: _mainController.selectedIndex,
|
||||||
onTap: (value) => setIndex(value),
|
onTap: (value) => setIndex(value),
|
||||||
iconSize: 16,
|
iconSize: 16,
|
||||||
selectedFontSize: 12,
|
selectedFontSize: 12,
|
||||||
|
Reference in New Issue
Block a user