363 lines
14 KiB
Dart
363 lines
14 KiB
Dart
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:get_storage/get_storage.dart';
|
||
import 'package:vbvs_app/common/color/appConstants.dart';
|
||
import 'package:vbvs_app/common/util/FitTool.dart';
|
||
import 'package:vbvs_app/common/util/MyUtils.dart';
|
||
import 'package:vbvs_app/component/tool/TopSlideNotification.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/message/message_controller.dart';
|
||
import 'package:vbvs_app/controller/setting/language/language_controller.dart';
|
||
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
|
||
import 'package:vbvs_app/controller/user_info_controller.dart';
|
||
import 'package:vbvs_app/enum/APPPackageType.dart';
|
||
import 'package:vbvs_app/enum/LoginStatus.dart';
|
||
import 'package:vbvs_app/pages/common/selectDialog.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/mh_page/component/mht_bind_dialog.dart';
|
||
|
||
class MainPageBottomChange extends GetView<MainPageController> {
|
||
GlobalController globalController = Get.find();
|
||
ThemeController themeController = Get.find();
|
||
MessageController messageController = Get.find();
|
||
final getStorage = GetStorage();
|
||
|
||
late final List<Widget> arr;
|
||
late final List<BottomNavigationBarItem> bottomItems;
|
||
DateTime? _lastBackPressedTime;
|
||
LanguageController languageController = Get.find();
|
||
bool select = false;//是否已经提示过升级弹窗
|
||
|
||
MainPageBottomChange({super.key}) {
|
||
// ✅ 根据是否测试账号动态生成页面
|
||
if (!AppConstants.is_test_account) {
|
||
arr = [
|
||
HomePage(),
|
||
EPage(sleepUri: "https://xiaoe.he-info.cn/"),
|
||
MessagePage(),
|
||
MinePage(),
|
||
];
|
||
bottomItems = [
|
||
getBottomNavigationBarItem("assets/img/menu/home.svg",
|
||
"assets/img/menu/n_home.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,
|
||
showBadge: true),
|
||
getBottomNavigationBarItem("assets/img/menu/mine.svg",
|
||
"assets/img/menu/n_mine.svg", "菜单.我的".tr),
|
||
];
|
||
} else {
|
||
arr = [
|
||
HomePage(),
|
||
MessagePage(),
|
||
MinePage(),
|
||
];
|
||
bottomItems = [
|
||
getBottomNavigationBarItem("assets/img/menu/home.svg",
|
||
"assets/img/menu/n_home.svg", "菜单.首页".tr),
|
||
getBottomNavigationBarItem("assets/img/menu/message.svg",
|
||
"assets/img/menu/n_message.svg", "菜单.消息".tr,
|
||
showBadge: (messageController.model.body_message_read == 1 ||
|
||
messageController.model.system_message_read == 1)),
|
||
getBottomNavigationBarItem("assets/img/menu/mine.svg",
|
||
"assets/img/menu/n_mine.svg", "菜单.我的".tr),
|
||
];
|
||
}
|
||
}
|
||
|
||
getBottomNavigationBarItem(String svgPath, String actSvgPath, String label,
|
||
{double size = 0, bool isEmpty = false, bool showBadge = false}) {
|
||
if (size == 0) size = 36.rpx;
|
||
|
||
Widget buildIcon(String path) {
|
||
return Obx(() {
|
||
int type1 = messageController.model.body_message_read!;
|
||
int type2 = messageController.model.system_message_read!;
|
||
return Padding(
|
||
padding: EdgeInsets.only(bottom: 6.rpx),
|
||
child: isEmpty
|
||
? Container()
|
||
: Stack(
|
||
clipBehavior: Clip.none,
|
||
children: [
|
||
SvgPicture.asset(
|
||
path,
|
||
width: size,
|
||
height: size,
|
||
),
|
||
if ((type1 == 1 || type2 == 1) && showBadge)
|
||
Positioned(
|
||
right: -20.rpx,
|
||
top: -2.rpx,
|
||
child: Container(
|
||
width: 14.rpx,
|
||
height: 14.rpx,
|
||
decoration: const BoxDecoration(
|
||
color: Colors.red,
|
||
shape: BoxShape.circle,
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
});
|
||
}
|
||
|
||
return BottomNavigationBarItem(
|
||
icon: buildIcon(actSvgPath),
|
||
activeIcon: buildIcon(svgPath),
|
||
label: label,
|
||
);
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
if (AppConstants().ent_type == APPPackageType.TH.code) {
|
||
Future.delayed(const Duration(milliseconds: 0), () {
|
||
String? isShowYingShiDialog = getStorage.read("isShowYingShiDialog");
|
||
if (isShowYingShiDialog == null || isShowYingShiDialog != "true") {
|
||
String btnName = "同意".tr;
|
||
String cancelName = "取消".tr;
|
||
if (Platform.isAndroid) cancelName = "退出".tr;
|
||
|
||
showCustomConfirmOfWebViewDialog(context, "隐私协议".tr, getPrivacy(1),
|
||
btnName: btnName, showCancel: true, cancelName: cancelName)
|
||
.then((e) {
|
||
if (e == "confirm") {
|
||
getStorage.write("isShowYingShiDialog", "true");
|
||
} else {
|
||
if (cancelName == "退出") SystemNavigator.pop();
|
||
}
|
||
});
|
||
}
|
||
if (select != true) {
|
||
//todo 判断APP是否需要更新
|
||
UserInfoController userInfoController = Get.find();
|
||
userInfoController
|
||
.checkAPPUpdate(AppConstants.theh_app_version)
|
||
.then((data) {
|
||
if (data != null) {
|
||
if (data['update'] != null && data['update'] == true) {
|
||
//需要更新
|
||
String updateUrl = data['updateUrl'];
|
||
try {
|
||
select = true;
|
||
showAPPUpgradeDialog(
|
||
// backgroundColor:themeController.currentColor.sc5,
|
||
context,
|
||
Column(
|
||
children: [
|
||
/// 上半部分:居中对齐
|
||
Column(
|
||
crossAxisAlignment: CrossAxisAlignment.center,
|
||
children: [
|
||
SizedBox(
|
||
width: 94.rpx,
|
||
height: 70.rpx,
|
||
child: SvgPicture.asset(
|
||
'assets/img/icon/upgrade.svg',
|
||
fit: BoxFit.cover,
|
||
),
|
||
),
|
||
SizedBox(height: 37.rpx),
|
||
Text(
|
||
"检测到新版本!".tr,
|
||
style: TextStyle(
|
||
color: stringToColor("#333333"),
|
||
fontSize: AppConstants().title_text_fontSize,
|
||
),
|
||
),
|
||
],
|
||
),
|
||
|
||
SizedBox(height: 37.rpx),
|
||
|
||
/// 下半部分:左对齐
|
||
Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Text("当前版本号".tr + ":" + "1.2.0"),
|
||
Text("升级后版本".tr + ":" + "1.2.0"),
|
||
Text(
|
||
"升级内容".tr +
|
||
":" +
|
||
"更新更新更新更新更新更新更新更新更新更新更新更新更新更新更新更新更新更新等...",
|
||
),
|
||
],
|
||
),
|
||
],
|
||
), onUpgradeTap: () {
|
||
if (Platform.isIOS) {
|
||
// 跳转AppStore
|
||
ef.log("msg");
|
||
} else {
|
||
//本地安装
|
||
ef.log("msg");
|
||
}
|
||
Get.back();
|
||
});
|
||
} catch (e) {
|
||
ef.log("msg");
|
||
}
|
||
}
|
||
}
|
||
});
|
||
}
|
||
});
|
||
}
|
||
|
||
return Obx(() {
|
||
final currentLanguage =
|
||
languageController.selectLanguage.value; // 监听此变量变化
|
||
return PopScope(
|
||
canPop: false,
|
||
onPopInvokedWithResult: (disposition, result) async {
|
||
UserInfoController userInfoController = Get.find();
|
||
if (userInfoController.model.isProgrammaticPop) {
|
||
userInfoController.model.isProgrammaticPop = false;
|
||
return;
|
||
}
|
||
|
||
// if (Platform.isAndroid) {
|
||
// Get.back();
|
||
// }
|
||
if (Platform.isAndroid) {
|
||
var flag = await _handleBackPressed(context);
|
||
if (flag) {
|
||
SystemNavigator.pop();
|
||
}
|
||
}
|
||
},
|
||
child: Obx(() {
|
||
int currentIndex = controller.model.currentIndex;
|
||
|
||
// ✅ 防止 index 超出范围(例如测试账号少一个 tab)
|
||
if (currentIndex >= arr.length) {
|
||
currentIndex = 0;
|
||
controller.model.currentIndex = 0;
|
||
}
|
||
|
||
if (globalController.model.hideBottomNavigationBar == true) {
|
||
return Scaffold(
|
||
body: IndexedStack(
|
||
index: currentIndex,
|
||
children:
|
||
arr.map((page) => SizedBox.expand(child: page)).toList(),
|
||
),
|
||
);
|
||
} else {
|
||
return Container(
|
||
decoration: const BoxDecoration(
|
||
image: DecorationImage(
|
||
image: AssetImage('assets/img/bgImage.png'),
|
||
fit: BoxFit.fill,
|
||
),
|
||
),
|
||
child: Scaffold(
|
||
backgroundColor: Colors.transparent,
|
||
body: IndexedStack(
|
||
index: currentIndex,
|
||
children:
|
||
arr.map((page) => SizedBox.expand(child: page)).toList(),
|
||
),
|
||
bottomNavigationBar: Theme(
|
||
data: Theme.of(context).copyWith(
|
||
splashFactory: NoSplash.splashFactory,
|
||
splashColor: Colors.transparent,
|
||
highlightColor: Colors.transparent,
|
||
),
|
||
child: Container(
|
||
decoration: BoxDecoration(
|
||
border: Border(
|
||
top: BorderSide(
|
||
color:
|
||
themeController.currentColor.sc4.withOpacity(0.5),
|
||
width: AppConstants().border_width,
|
||
),
|
||
),
|
||
),
|
||
child: BottomNavigationBar(
|
||
unselectedItemColor: themeController.currentColor.sc4,
|
||
selectedItemColor: themeController.currentColor.sc1,
|
||
backgroundColor: themeController.currentColor.sc5,
|
||
selectedFontSize: 26.rpx,
|
||
unselectedFontSize: 26.rpx,
|
||
type: BottomNavigationBarType.fixed,
|
||
currentIndex: currentIndex,
|
||
onTap: (index) {
|
||
Future.delayed(const Duration(milliseconds: 100), () {
|
||
UserInfoController userInfoController = Get.find();
|
||
bool isLoggedIn = userInfoController.model.login ==
|
||
LoginStatus.LOGIN.code;
|
||
|
||
// ✅ 仅非测试账号检查登录状态
|
||
if (!AppConstants.is_test_account &&
|
||
(index == 2) &&
|
||
!isLoggedIn) {
|
||
TopSlideNotification.show(
|
||
context,
|
||
text: "必须登录提示".tr,
|
||
textColor: themeController.currentColor.sc9,
|
||
);
|
||
Future.delayed(const Duration(milliseconds: 50),
|
||
() {
|
||
if (Get.currentRoute == '/ePage' ||
|
||
Get.currentRoute == '/messagePage') {
|
||
Get.back();
|
||
}
|
||
Future.delayed(const Duration(milliseconds: 100),
|
||
() {
|
||
Get.toNamed("/otherLoginPage");
|
||
});
|
||
});
|
||
return;
|
||
}
|
||
|
||
if (controller.model.currentIndex != index) {
|
||
globalController.model.hideBottomNavigationBar =
|
||
false;
|
||
globalController.updateAll();
|
||
}
|
||
|
||
controller.model.currentIndex = index;
|
||
controller.updateAll();
|
||
});
|
||
},
|
||
items: bottomItems,
|
||
),
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}),
|
||
);
|
||
});
|
||
}
|
||
|
||
Future<bool> _handleBackPressed(BuildContext context) async {
|
||
final currentTime = DateTime.now();
|
||
if (_lastBackPressedTime == null ||
|
||
currentTime.difference(_lastBackPressedTime!) >
|
||
const Duration(seconds: 2)) {
|
||
_lastBackPressedTime = currentTime;
|
||
TopSlideNotification.show(context, text: "滑动退出提醒".tr);
|
||
return false;
|
||
} else {
|
||
return true;
|
||
}
|
||
}
|
||
}
|