import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import '../../../../app_settings/app_colors.dart'; import '../../../../tools/submitBtn.dart'; import '../../../../tools/titleAppBar.dart'; import 'lockEscalation_logic.dart'; class LockEscalationPage extends StatefulWidget { const LockEscalationPage({Key? key}) : super(key: key); @override State createState() => _LockEscalationPageState(); } class _LockEscalationPageState extends State { @override Widget build(BuildContext context) { return GetBuilder( init: LockEscalationLogic(), builder: (LockEscalationLogic logic) { return Scaffold( backgroundColor: Colors.white, appBar: TitleAppBar( barTitle: '锁升级'.tr, haveBack: true, backgroundColor: AppColors.mainColor, backAction: logic.getBack, ), body: Container( padding: EdgeInsets.all(30.w), child: Obx(() { return updateView(logic); }), )); }); } Widget updateView(LockEscalationLogic logic) { if (logic.state.loading.value) { return Padding( padding: EdgeInsets.only(top: 60.h), child: Align( alignment: Alignment.topCenter, child: Column( children: [ Text( '加载数据中'.tr, style: TextStyle(fontSize: 24.sp, fontWeight: FontWeight.w600), ), SizedBox( height: 40.h, ), CircularProgressIndicator( color: AppColors.mainColor, ), ], ), ), ); } if (logic.state.otaUpdateIng.value) { return otaUpdate(logic); } if (logic.model == '') { return Padding( padding: EdgeInsets.only(top: 60.h), child: Column( children: [ Text( '加载数据失败'.tr, style: TextStyle(fontSize: 24.sp, fontWeight: FontWeight.w600), ), SizedBox( height: 40.h, ), SubmitBtn( btnName: '重试'.tr, onClick: () { logic.getStarLockStatus(); }), ], ), ); } return defaultUpdate(logic); } //升级 Widget defaultUpdate(LockEscalationLogic logic) { return Column( children: [ SizedBox( height: 60.h, ), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Image.asset( 'images/main/icon_main_lockSet_lockEscalation.png', width: 36.w, height: 36.w, ), SizedBox( width: 10.w, ), Obx(() { if (logic.state.isShowUpDataBtn.value) { return Text( '有新版本'.tr + logic.state.showNewVersion.value, style: TextStyle(fontSize: 24.sp, fontWeight: FontWeight.w600), ); } else { return Text( '已是最新版本'.tr, style: TextStyle(fontSize: 24.sp, fontWeight: FontWeight.w600), ); } }) ], ), SizedBox( height: 30.h, ), Obx(() { return Text( '${'当前版本'.tr}:${logic.state.showVersion.value}', style: TextStyle(fontSize: 18.sp, color: AppColors.darkGrayTextColor), ); }), SizedBox( height: 40.h, ), Obx(() { final bool show = !logic.state.otaUpdateIng.value && logic.state.isShowUpDataBtn.value; return show ? SubmitBtn( btnName: '升级'.tr, onClick: () { logic.downloadTheFile(); }) : const SizedBox(); }), SizedBox( height: 10.h, ), Align( alignment: Alignment.topRight, child: GestureDetector( onTap: () { logic.otaUpdate(); }, child: Padding( padding: const EdgeInsets.all(8.0), child: Text( '手动升级'.tr, style: TextStyle( color: AppColors.mainColor, fontSize: 18.sp, fontWeight: FontWeight.w400), ), ), ), ), ], ); } //ota升级 Widget otaUpdate(LockEscalationLogic logic) { return Column( children: [ SizedBox( height: 20.h, ), Text( '${'机型'.tr}:${logic.headJson?['platform']}', style: TextStyle( color: AppColors.blackColor, fontSize: 22.sp, fontWeight: FontWeight.w600), ), SizedBox( height: 10.h, ), Text( '${'固件版本'.tr}:${logic.headJson?['fwVersion']}', style: TextStyle( color: AppColors.blackColor, fontSize: 22.sp, fontWeight: FontWeight.w600), ), SizedBox( height: 20.h, ), Text( '传输期间请勿离开当前页面'.tr, style: TextStyle( color: AppColors.blackColor, fontSize: 20.sp, fontWeight: FontWeight.w400), ), Padding( padding: EdgeInsets.symmetric(horizontal: 50.w, vertical: 15.h), child: Row( mainAxisSize: MainAxisSize.min, children: [ Text( '固件传输中'.tr, style: TextStyle( color: AppColors.mainColor, fontSize: 18.sp, fontWeight: FontWeight.w400), ), SizedBox( width: 10.w, ), Expanded( child: ClipRRect( borderRadius: BorderRadius.all(Radius.circular(10.r)), child: LinearProgressIndicator( value: logic.state.otaProgress.value, // 50% 进度 backgroundColor: Colors.grey[200], valueColor: AlwaysStoppedAnimation(AppColors.mainColor), ), ), ), ], ), ), ], ); } }