466 lines
23 KiB
Dart
466 lines
23 KiB
Dart
import 'dart:io';
|
||
|
||
import 'package:ef/base/widget/flutterflow/FlutterFlowTheme.dart';
|
||
import 'package:ef/ef.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter/services.dart';
|
||
import 'package:flutterflow_ui/flutterflow_ui.dart';
|
||
import 'package:fluwx/fluwx.dart';
|
||
import 'package:vbvs_app/common/color/ServiceConstant.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/common/util/requestWithLog.dart';
|
||
import 'package:vbvs_app/component/tool/CustomCard.dart';
|
||
import 'package:vbvs_app/component/tool/TopSlideNotification.dart';
|
||
import 'package:vbvs_app/controller/mh_controller/device_list_controller.dart';
|
||
import 'package:vbvs_app/controller/mh_controller/mhdevice_share_controller.dart';
|
||
import 'package:vbvs_app/pages/mh_page/test/WebviewTestModel.dart';
|
||
|
||
import '../../common/color/appFontsize.dart';
|
||
|
||
class ShareDeviceDetailWidget extends GetView {
|
||
final scaffoldKey = GlobalKey<ScaffoldState>();
|
||
Map data;
|
||
ShareDeviceDetailWidget({super.key, required this.data});
|
||
getLine() {
|
||
return Divider(
|
||
color: const Color(0XFF929699),
|
||
thickness: 0.5.rpx,
|
||
);
|
||
}
|
||
|
||
var opType = 1.obs;
|
||
bool isProgrammaticPop = false; // 标记变量
|
||
DateTime? _lastBackPressedTime; // 记录上一次返回的时间
|
||
DeviceListController deviceListController = Get.find();
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
opType.value = data['info'][3]['opType'];
|
||
return GestureDetector(
|
||
// onTap: () => FocusScope.of(context).unfocus(),,
|
||
child: Container(
|
||
decoration: const BoxDecoration(
|
||
image: DecorationImage(
|
||
image: AssetImage('assets/images/new_background.png'), // 本地图片
|
||
fit: BoxFit.fill, // 填满整个 Container
|
||
),
|
||
),
|
||
child: Scaffold(
|
||
key: scaffoldKey,
|
||
backgroundColor: Colors.transparent,
|
||
appBar: AppBar(
|
||
backgroundColor: Colors.transparent,
|
||
automaticallyImplyLeading: false,
|
||
iconTheme: const IconThemeData(color: Colors.white),
|
||
titleSpacing: 0,
|
||
title: SizedBox(
|
||
width: double.infinity,
|
||
height: 180.rpx,
|
||
child: Stack(
|
||
alignment: Alignment.center,
|
||
children: [
|
||
// 中间居中的标题
|
||
Text(
|
||
'详情'.tr,
|
||
textAlign: TextAlign.center,
|
||
style: TextStyle(
|
||
color: Colors.white,
|
||
fontSize: 30.rpx,
|
||
),
|
||
),
|
||
// 左侧图标
|
||
Positioned(
|
||
left: 0.rpx,
|
||
child: returnIconButtomNew(onBack: () async {
|
||
try {
|
||
String serviceAddress = ServiceConstant.service_address;
|
||
String serviceName = ServiceConstant.server_service;
|
||
String serviceApi = ServiceConstant.device_show;
|
||
String queryUrl =
|
||
"$serviceAddress$serviceName$serviceApi";
|
||
await requestWithLog(
|
||
logTitle: "更新设备信息".tr,
|
||
method: MyHttpMethod.put,
|
||
queryUrl: queryUrl,
|
||
data: {
|
||
"id": data['info'][4]["id"],
|
||
"opType": opType.value
|
||
},
|
||
onSuccess: (res) {
|
||
TopSlideNotification.show(context,
|
||
text: "更新成功".tr, textColor: Color(0XFF00C1AA));
|
||
deviceListController.getDeviceList();
|
||
try {
|
||
WebviewTestController webviewTestController =
|
||
Get.find();
|
||
webviewTestController.web.jsbridge?.dart
|
||
.alterDevice();
|
||
} catch (e) {
|
||
ef.log("[h5]通知列表更新错误:$e");
|
||
}
|
||
},
|
||
onFailure: (res) {
|
||
TopSlideNotification.show(context,
|
||
text: "更新失败".tr, textColor: Color(0xFFFF7159));
|
||
},
|
||
);
|
||
} catch (e) {
|
||
print(e);
|
||
}
|
||
}),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
centerTitle: false,
|
||
),
|
||
body: PopScope(
|
||
canPop: false,
|
||
onPopInvokedWithResult: (disposition, result) async {
|
||
if (isProgrammaticPop) {
|
||
// 如果是程序触发,重置标记并忽略
|
||
isProgrammaticPop = false;
|
||
return; // 阻止处理
|
||
}
|
||
try {
|
||
String serviceAddress = ServiceConstant.service_address;
|
||
String serviceName = ServiceConstant.server_service;
|
||
String serviceApi = ServiceConstant.device_show;
|
||
String queryUrl = "$serviceAddress$serviceName$serviceApi";
|
||
await requestWithLog(
|
||
logTitle: "更新设备信息".tr,
|
||
method: MyHttpMethod.put,
|
||
queryUrl: queryUrl,
|
||
data: {"id": data['info'][4]["id"], "opType": opType.value},
|
||
onSuccess: (res) {
|
||
TopSlideNotification.show(context,
|
||
text: "更新成功".tr, textColor: Color(0XFF00C1AA));
|
||
deviceListController.getDeviceList();
|
||
try {
|
||
WebviewTestController webviewTestController = Get.find();
|
||
webviewTestController.web.jsbridge?.dart.alterDevice();
|
||
} catch (e) {
|
||
ef.log("[h5]通知列表更新错误:$e");
|
||
}
|
||
isProgrammaticPop = true; // 设置为程序触发,避免再次触发 PopScope
|
||
Get.back(); // 或 Navigator.pop(context);
|
||
},
|
||
onFailure: (res) {
|
||
TopSlideNotification.show(context,
|
||
text: "更新失败".tr, textColor: Color(0xFFFF7159));
|
||
},
|
||
);
|
||
} catch (e) {
|
||
print(e);
|
||
}
|
||
// if (Platform.isAndroid) {
|
||
// var flag = await _handleBackPressed(context); // 自定义返回逻辑
|
||
// if (flag) {
|
||
// SystemNavigator.pop();
|
||
// }
|
||
// }
|
||
},
|
||
child: Container(
|
||
width: MediaQuery.sizeOf(context).width,
|
||
height: MediaQuery.sizeOf(context).height * 1,
|
||
child: Padding(
|
||
padding:
|
||
EdgeInsetsDirectional.fromSTEB(30.rpx, 34.rpx, 30.rpx, 0),
|
||
child: Column(
|
||
mainAxisSize: MainAxisSize.max,
|
||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
children: [
|
||
Container(
|
||
width: MediaQuery.sizeOf(context).width,
|
||
decoration: BoxDecoration(
|
||
borderRadius: BorderRadius.circular(8),
|
||
),
|
||
child: Column(
|
||
mainAxisSize: MainAxisSize.max,
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Padding(
|
||
padding: EdgeInsetsDirectional.only(
|
||
start: 27.rpx, bottom: 18.rpx),
|
||
child: Column(
|
||
mainAxisSize: MainAxisSize.max,
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Text(
|
||
data['info'][0]['v'],
|
||
// '${shareInfo['userName']}',
|
||
style: FlutterFlowTheme.of(context)
|
||
.bodyMedium
|
||
.override(
|
||
fontFamily: 'Readex Pro',
|
||
color: const Color(0xFFFFFFFF),
|
||
fontSize: 28.rpx,
|
||
letterSpacing: 0.0,
|
||
),
|
||
),
|
||
Text(
|
||
'分享时间:${data['info'][2]['v']}',
|
||
style: FlutterFlowTheme.of(context)
|
||
.bodyMedium
|
||
.override(
|
||
fontFamily: 'Readex Pro',
|
||
color: const Color(0xFF9EA4B7),
|
||
fontSize: 20.rpx,
|
||
letterSpacing: 0.0,
|
||
),
|
||
),
|
||
].divide(SizedBox(height: 10.rpx)),
|
||
),
|
||
),
|
||
getLine(),
|
||
SizedBox(
|
||
height: 25.rpx,
|
||
),
|
||
Container(
|
||
decoration: BoxDecoration(
|
||
color: Color(0xFF003058),
|
||
borderRadius: BorderRadius.circular(16.rpx)),
|
||
child: Padding(
|
||
padding: EdgeInsetsDirectional.only(
|
||
start: 38.rpx,
|
||
top: 50.rpx,
|
||
end: 30.rpx,
|
||
bottom: 30.rpx),
|
||
child: Column(
|
||
children: [
|
||
GestureDetector(
|
||
onTap: () {
|
||
// 当点击时,将 type 设置为 0(允许控制)
|
||
|
||
data['info'][3]['opType'] = 1;
|
||
opType.value = 1;
|
||
},
|
||
child: Container(
|
||
width: MediaQuery.sizeOf(context).width,
|
||
constraints: const BoxConstraints(
|
||
minHeight: 46,
|
||
),
|
||
decoration: BoxDecoration(
|
||
borderRadius:
|
||
BorderRadius.circular(0),
|
||
),
|
||
child: Row(
|
||
mainAxisSize: MainAxisSize.max,
|
||
mainAxisAlignment:
|
||
MainAxisAlignment.spaceBetween,
|
||
children: [
|
||
Text(
|
||
'允许对方控制和查看该设备'.tr,
|
||
style: FlutterFlowTheme.of(
|
||
context)
|
||
.bodyMedium
|
||
.override(
|
||
fontFamily: 'Readex Pro',
|
||
color:
|
||
const Color(0xFFFFFFFF),
|
||
fontSize: 27.rpx,
|
||
letterSpacing: 0.0,
|
||
),
|
||
),
|
||
Obx(() {
|
||
return Container(
|
||
height: 33.rpx,
|
||
child: AspectRatio(
|
||
aspectRatio: 1,
|
||
child: Center(
|
||
child: Container(
|
||
height: 33.rpx,
|
||
width: 33.rpx,
|
||
decoration: BoxDecoration(
|
||
borderRadius:
|
||
BorderRadius
|
||
.circular(
|
||
33.rpx / 2),
|
||
border: Border.all(
|
||
width:
|
||
opType.value == 1
|
||
? 1
|
||
: 0.5,
|
||
color:
|
||
Color(0xFFC8CBD2),
|
||
),
|
||
),
|
||
child: opType.value == 1
|
||
? Center(
|
||
child: ClipOval(
|
||
child:
|
||
Container(
|
||
width:
|
||
33.rpx *
|
||
0.6,
|
||
height:
|
||
33.rpx *
|
||
0.6,
|
||
color: const Color(
|
||
0xFF6BFDAC),
|
||
),
|
||
),
|
||
)
|
||
: null,
|
||
),
|
||
),
|
||
),
|
||
);
|
||
})
|
||
],
|
||
),
|
||
),
|
||
),
|
||
GestureDetector(
|
||
onTap: () {
|
||
// 当点击时,将 type 设置为 1(仅允许查看)
|
||
data['info'][3]['opType'] = 2;
|
||
opType.value = 2;
|
||
},
|
||
child: Container(
|
||
width: MediaQuery.sizeOf(context).width,
|
||
constraints: const BoxConstraints(
|
||
minHeight: 46,
|
||
),
|
||
decoration: BoxDecoration(
|
||
borderRadius:
|
||
BorderRadius.circular(0),
|
||
),
|
||
child: Row(
|
||
mainAxisSize: MainAxisSize.max,
|
||
mainAxisAlignment:
|
||
MainAxisAlignment.spaceBetween,
|
||
children: [
|
||
Text(
|
||
'仅允许对方查看该设备'.tr,
|
||
style: FlutterFlowTheme.of(
|
||
context)
|
||
.bodyMedium
|
||
.override(
|
||
fontFamily: 'Readex Pro',
|
||
color:
|
||
const Color(0xFFFFFFFF),
|
||
fontSize: 27.rpx,
|
||
letterSpacing: 0.0,
|
||
),
|
||
),
|
||
Obx(() {
|
||
return Container(
|
||
height: 33.rpx,
|
||
child: AspectRatio(
|
||
aspectRatio: 1,
|
||
child: Center(
|
||
child: Container(
|
||
height: 33.rpx,
|
||
width: 33.rpx,
|
||
decoration: BoxDecoration(
|
||
borderRadius:
|
||
BorderRadius
|
||
.circular(
|
||
33.rpx / 2),
|
||
border: Border.all(
|
||
width:
|
||
opType.value == 2
|
||
? 1
|
||
: 0.5,
|
||
color:
|
||
Color(0xFFC8CBD2),
|
||
),
|
||
),
|
||
child: opType.value == 2
|
||
? Center(
|
||
child: ClipOval(
|
||
child:
|
||
Container(
|
||
width:
|
||
33.rpx *
|
||
0.6,
|
||
height:
|
||
33.rpx *
|
||
0.6,
|
||
color: const Color(
|
||
0xFF6BFDAC),
|
||
),
|
||
),
|
||
)
|
||
: null,
|
||
),
|
||
),
|
||
),
|
||
);
|
||
})
|
||
],
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
))
|
||
|
||
]),
|
||
),
|
||
Padding(
|
||
padding: const EdgeInsetsDirectional.fromSTEB(
|
||
0, 0, 0, AppConstants.page_button_bottom_padding),
|
||
child: Container(
|
||
width: MediaQuery.sizeOf(context).width,
|
||
height: MediaQuery.sizeOf(context).height * 0.056,
|
||
constraints: const BoxConstraints(
|
||
minHeight: 46,
|
||
),
|
||
decoration: BoxDecoration(
|
||
color: FlutterFlowTheme.of(context).secondaryBackground,
|
||
borderRadius: BorderRadius.circular(16.rpx),
|
||
),
|
||
child: Container(
|
||
width: MediaQuery.sizeOf(context).width,
|
||
height: MediaQuery.sizeOf(context).height * 0.056,
|
||
decoration: BoxDecoration(
|
||
color: FlutterFlowTheme.of(context)
|
||
.secondaryBackground,
|
||
borderRadius: BorderRadius.circular(16.rpx),
|
||
),
|
||
child: CustomCard(
|
||
borderRadius: 16.rpx,
|
||
gradientDirection: GradientDirection.vertical,
|
||
onTap: () async {
|
||
deviceListController.unbindShareDevice(
|
||
data['info'][5]['uid'],
|
||
data['mac'.tr],
|
||
context);
|
||
|
||
},
|
||
colors: const [
|
||
Color(0xFFFCFCFC),
|
||
Color(0xFFF8FAF9),
|
||
Color(0XFFECF6F3),
|
||
Color(0XFFD9F0E9),
|
||
Color(0xFFCEECE3)
|
||
],
|
||
child: Container(
|
||
width: double.infinity,
|
||
height: 90.rpx,
|
||
alignment: Alignment.center,
|
||
decoration: BoxDecoration(
|
||
borderRadius: BorderRadius.circular(16.rpx),
|
||
),
|
||
child: Text("解除分享".tr,
|
||
style: TextStyle(
|
||
color: const Color(0xFF003058),
|
||
fontSize: 30.rpx,
|
||
)),
|
||
),
|
||
)),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
));
|
||
}
|
||
}
|