import 'dart:async'; import 'package:dating_touchme_app/controller/global.dart'; import 'package:dating_touchme_app/controller/message/conversation_controller.dart'; import 'package:dating_touchme_app/controller/discover/room_controller.dart'; import 'package:dating_touchme_app/controller/overlay_controller.dart'; import 'package:dating_touchme_app/im/im_manager.dart'; import 'package:dating_touchme_app/extension/ex_widget.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:get_storage/get_storage.dart'; import 'package:tdesign_flutter/tdesign_flutter.dart'; import '../../generated/assets.dart'; import 'package:package_info_plus/package_info_plus.dart'; import '../../model/mine/app_version.dart'; import '../../network/user_api.dart'; class SettingController extends GetxController { final storage = GetStorage(); final appName = ''.obs; final packageName = ''.obs; final version = ''.obs; final buildNumber = ''.obs; // UserApi实例 late UserApi _userApi; @override Future onInit() async { super.onInit(); // 从全局依赖中获取UserApi _userApi = Get.find(); await getAppInfo(); } // 获取验证码 Future getAppInfo() async { try { PackageInfo packageInfo = await PackageInfo.fromPlatform(); appName.value = packageInfo.appName; packageName.value = packageInfo.packageName; version.value = packageInfo.version; buildNumber.value = packageInfo.buildNumber; } catch (e) { print('获取应用信息失败: $e'); } } Future checkVersion() async { try { final response = await _userApi.getAppVersionInfo(os: 1, code: int.parse(buildNumber.value)); print(response); if (response.data.isSuccess && response.data.data != null) { AppVersion version = response.data.data!; _showUpdateDialog(version); } } catch (e) { print('检测版本跟新失败: $e'); } } void logout() async { // 退出直播间 if (Get.isRegistered()) { try { final roomController = Get.find(); await roomController.leaveChannel(); } catch (e) { print('退出直播间失败: $e'); } } // 取消小窗口 if (Get.isRegistered()) { try { final overlayController = Get.find(); overlayController.hide(); // 隐藏直播房间小窗 overlayController.hideVideoCall(); // 隐藏视频通话小窗 } catch (e) { print('取消小窗口失败: $e'); } } // 先退出 IM 登录 await IMManager.instance.logout(); // 清除会话列表和用户信息缓存 if (Get.isRegistered()) { final conversationController = Get.find(); conversationController.clearConversations(); } // App清除本地存储,有待处理, // storage.erase(); storage.remove('userId'); storage.remove('token'); // storage.write('hasAgreedUserAgreement', true); // 清除全局数据 GlobalData().logout(); } void updateApplication(){ } // 弹出版本升级的dialog void _showUpdateDialog(AppVersion version){ Navigator.of(Get.context!).push(TDSlidePopupRoute( modalBarrierColor: TDTheme.of(Get.context!).fontGyColor2, slideTransitionFrom: SlideTransitionFrom.center, builder: (context) { return Material( color: Colors.transparent, child: Container( color: Colors.transparent, width: 299.w, padding: EdgeInsets.only(top: 56.w), child: Stack( clipBehavior: Clip.none, children: [ Container( width: 299.w, padding: EdgeInsets.only( top: 147.w, left: 30.w, right: 30.w, bottom: 25.w ), decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(18.w)), color: Colors.white ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ Text( version.title!, style: TextStyle( fontSize: 16.w, fontWeight: FontWeight.w500 ), ), SizedBox(height: 14.w,), Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ SizedBox( width: 204.w, child: Text( version.description!, style: TextStyle( fontSize: 12.w, ), ), ) ], ), SizedBox(height: 32.w,), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Container( width: 113.w, height: 40.w, decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(9.w)), color: const Color.fromRGBO(245, 245, 245, 1) ), child: Center( child: Text( "暂不更新", style: TextStyle( fontSize: 15.w, color: const Color.fromRGBO(144, 144, 144, 1) ), ), ), ).onTap((){ Navigator.of(context).pop(); }), Container( width: 113.w, height: 40.w, decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(9.w)), color: const Color.fromRGBO(245, 245, 245, 1), gradient: const LinearGradient( begin: Alignment.centerLeft, end: Alignment.centerRight, // 对应 CSS 90deg colors: [ Color.fromRGBO(131, 89, 255, 1), // rgba(131, 89, 255, 1) Color.fromRGBO(61, 138, 224, 1), // rgba(61, 138, 224, 1) ], ), ), child: Center( child: Text( "立即升级", style: TextStyle( fontSize: 15.w, fontWeight: FontWeight.w500, color: Colors.white ), ), ), ).onTap((){ updateApplication(); }), ], ) ], ), ), Positioned( left: 0, top: -56.w, child: Image.asset( Assets.imagesUpdataBg, width: 299.w, ), ), Positioned( left: 11.w, top: -14.w, child: Image.asset( Assets.imagesUpdataIcon, width: 36.w, ), ), Positioned( left: 43.w, top: 29.w, child: Image.asset( Assets.imagesUpdataFont, width: 76.w, ), ) ], ), ), ); })); } }