初始化项目
This commit is contained in:
192
lib/pages/main_bottom/main_page_bottom_change.dart
Normal file
192
lib/pages/main_bottom/main_page_bottom_change.dart
Normal file
@@ -0,0 +1,192 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:ef/ef.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:vbvs_app/common/util/FitTool.dart';
|
||||
import 'package:vbvs_app/common/util/MyUtils.dart';
|
||||
import 'package:vbvs_app/controller/main_bottom/global_controller.dart';
|
||||
import 'package:vbvs_app/controller/main_bottom/main_page_controller.dart';
|
||||
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
|
||||
import 'package:vbvs_app/pages/main_bottom/e_page.dart';
|
||||
import 'package:vbvs_app/pages/main_bottom/home_page.dart';
|
||||
import 'package:vbvs_app/pages/main_bottom/message_page.dart';
|
||||
import 'package:vbvs_app/pages/main_bottom/mine_page.dart';
|
||||
import 'package:vbvs_app/pages/main_bottom/sleep_report_page.dart';
|
||||
|
||||
class MainPageBottomChange extends GetView<MainPageController> {
|
||||
GlobalController globalController = Get.find();
|
||||
ThemeController themeController = Get.find();
|
||||
getBottomNavigationBarItem(String svgPath, String actSvgPath, String label,
|
||||
{double size = 0, bool isEmpty = false}) {
|
||||
if (size == 0) {
|
||||
size = 36.rpx;
|
||||
}
|
||||
return BottomNavigationBarItem(
|
||||
icon: Padding(
|
||||
padding: EdgeInsets.only(bottom: 6.rpx),
|
||||
child: isEmpty
|
||||
? Container()
|
||||
: SvgPicture.asset(
|
||||
actSvgPath,
|
||||
width: size,
|
||||
height: size,
|
||||
),
|
||||
),
|
||||
// activeIcon: Padding(
|
||||
// padding: EdgeInsets.only(bottom: 6.rpx),
|
||||
// child: isEmpty
|
||||
// ? Container()
|
||||
// : SvgPicture.asset(
|
||||
// svgPath,
|
||||
// color: stringToColor("#D3B684"),
|
||||
// width: size,
|
||||
// height: size,
|
||||
// ),
|
||||
// ),
|
||||
activeIcon: Padding(
|
||||
padding: EdgeInsets.only(bottom: 6.rpx),
|
||||
child: isEmpty
|
||||
? Container()
|
||||
: SvgPicture.asset(
|
||||
svgPath,
|
||||
width: size,
|
||||
height: size,
|
||||
),
|
||||
),
|
||||
label: label);
|
||||
}
|
||||
|
||||
List arr = [
|
||||
HomePage(),
|
||||
SleepReportPage(),
|
||||
EPage(),
|
||||
MessagePage(),
|
||||
MinePage(),
|
||||
];
|
||||
|
||||
DateTime? _lastBackPressedTime; // 记录上一次返回的时间
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (disposition, result) async {
|
||||
if (Platform.isAndroid) {
|
||||
var flag = await _handleBackPressed(context); // 自定义返回逻辑
|
||||
if (flag) {
|
||||
SystemNavigator.pop();
|
||||
}
|
||||
}
|
||||
},
|
||||
child: Obx(
|
||||
() {
|
||||
if (globalController.model.hideBottomNavigationBar == true) {
|
||||
return Scaffold(
|
||||
body: arr[controller.model.currentIndex],
|
||||
floatingActionButtonAnimator:
|
||||
FloatingActionButtonAnimator.noAnimation,
|
||||
floatingActionButton: Container(),
|
||||
);
|
||||
} else {
|
||||
return Scaffold(
|
||||
body: arr[controller.model.currentIndex],
|
||||
floatingActionButtonAnimator:
|
||||
FloatingActionButtonAnimator.noAnimation,
|
||||
// floatingActionButton: Stack(
|
||||
// alignment: Alignment.center,
|
||||
// children: [
|
||||
// Positioned(
|
||||
// bottom: 10.rpx,
|
||||
// child: InkWell(
|
||||
// onTap: () {
|
||||
// print("index 3");
|
||||
// if (globalController.model.deviceList.length == 0) {
|
||||
// showToast("请先绑定设备");
|
||||
// return;
|
||||
// }
|
||||
// if (globalController.model.deviceMain == null ||
|
||||
// globalController.model.deviceMain["mac"] == null) {
|
||||
// globalController.model.deviceMain =
|
||||
// globalController.model.deviceList[0];
|
||||
// globalController.updateAll();
|
||||
// }
|
||||
|
||||
// controller.model.currentIndex = 2;
|
||||
// controller.updateAll();
|
||||
// },
|
||||
// child: Image.asset(
|
||||
// gaplessPlayback: true,
|
||||
// excludeFromSemantics: true,
|
||||
// controller.model.currentIndex == 2
|
||||
// ? "assets/images/icon_sleep_light.png"
|
||||
// : "assets/images/icon_sleep_dark.png",
|
||||
// width: 120.rpx,
|
||||
// height: 120.rpx,
|
||||
// ),
|
||||
// )),
|
||||
// ],
|
||||
// ),
|
||||
floatingActionButtonLocation:
|
||||
FloatingActionButtonLocation.centerDocked,
|
||||
bottomNavigationBar: Theme(
|
||||
data: ThemeData(
|
||||
splashFactory: NoSplash.splashFactory,
|
||||
highlightColor: Colors.transparent),
|
||||
child: BottomNavigationBar(
|
||||
unselectedItemColor: Colors.white,
|
||||
selectedItemColor: stringToColor("#D3B684"),
|
||||
backgroundColor: themeController.currentColor.sc5,
|
||||
selectedFontSize: 26.rpx,
|
||||
unselectedFontSize: 26.rpx,
|
||||
type: BottomNavigationBarType.fixed,
|
||||
currentIndex: controller.model.currentIndex,
|
||||
onTap: (index) {
|
||||
// if(controller.model.currentIndex == 2) {
|
||||
// arr[2].closeBefore();
|
||||
// }
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
if (controller.model.currentIndex != 1) {
|
||||
globalController.model.hideBottomNavigationBar = false;
|
||||
globalController.updateAll();
|
||||
}
|
||||
});
|
||||
controller.model.currentIndex = index;
|
||||
controller.updateAll();
|
||||
},
|
||||
items: [
|
||||
getBottomNavigationBarItem("assets/img/menu/home.svg",
|
||||
"assets/img/menu/n_home.svg", "菜单.首页".tr),
|
||||
getBottomNavigationBarItem("assets/img/menu/report.svg",
|
||||
"assets/img/menu/n_report.svg", "菜单.报告".tr),
|
||||
getBottomNavigationBarItem("assets/img/menu/e.svg",
|
||||
"assets/img/menu/n_e.svg", "菜单.小e".tr),
|
||||
getBottomNavigationBarItem("assets/img/menu/message.svg",
|
||||
"assets/img/menu/n_message.svg", "菜单.消息".tr),
|
||||
getBottomNavigationBarItem("assets/img/menu/mine.svg",
|
||||
"assets/img/menu/n_mine.svg", "菜单.我的".tr),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<bool> _handleBackPressed(BuildContext context) async {
|
||||
final currentTime = DateTime.now();
|
||||
|
||||
// 如果上次点击返回键时间为空,或者间隔超过 1 秒
|
||||
if (_lastBackPressedTime == null ||
|
||||
currentTime.difference(_lastBackPressedTime!) > Duration(seconds: 2)) {
|
||||
_lastBackPressedTime = currentTime;
|
||||
showToast("再按一次退出程序", color: color_warning, closeTime: 2);
|
||||
return false; // 阻止退出程序
|
||||
} else {
|
||||
return true; // 允许退出程序
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user