更新页面

This commit is contained in:
wyf
2025-04-16 14:27:10 +08:00
parent 146462b467
commit 1765403f21
58 changed files with 7821 additions and 433 deletions

View File

@@ -0,0 +1,502 @@
import 'dart:async';
import 'package:ef/ef.dart';
import 'package:flutter/material.dart';
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
import 'package:flutterflow_ui/flutterflow_ui.dart';
import 'package:vbvs_app/common/color/appConstants.dart';
import 'package:vbvs_app/common/util/Ble.dart';
import 'package:vbvs_app/common/util/FitTool.dart';
import 'package:vbvs_app/common/util/MyUtils.dart';
import 'package:vbvs_app/component/tool/CustomCard.dart';
import 'package:vbvs_app/controller/device/blueteeth_bind_controller.dart';
import 'package:vbvs_app/controller/main_bottom/global_controller.dart';
import 'package:vbvs_app/controller/person/person_controller.dart';
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
import 'package:vbvs_app/controller/user_info_controller.dart';
import 'package:vbvs_app/common/util/Ble.dart' as ble;
import 'package:vbvs_app/pages/common/selectDialog.dart';
class WifiPage extends StatefulWidget {
// ble.ConnectedDeviceProp connectedDeviceProp;
BluetoothDevice bluetoothDevice;
// WifiPage({super.key, required this.connectedDeviceProp});
WifiPage({super.key, required this.bluetoothDevice});
@override
State<WifiPage> createState() => _WifiPageState();
}
class _WifiPageState extends State<WifiPage> {
GlobalController globalController = Get.find();
UserInfoController userInfoController = Get.find();
BlueteethBindController blueteethBindController = Get.find();
PersonController personController = Get.find();
ThemeController themeController = Get.find();
late ble.ConnectedDeviceProp connectedDeviceProp;
@override
void initState() {
super.initState();
connectToDevice(widget.bluetoothDevice);
// connectedDeviceProp = widget.connectedDeviceProp;
Timer(const Duration(microseconds: 100), () {
getWifiList();
});
}
@override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, bodySize) => GestureDetector(
onTap: () => FocusScope.of(context).unfocus(),
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/img/bgNoImg.png'), // 本地图片
fit: BoxFit.fill, // 填满整个 Container
),
),
child: Scaffold(
backgroundColor: Colors.transparent, // 加上这一行
appBar: AppBar(
backgroundColor: stringToColor("#242835"),
// backgroundColor: Colors.transparent,
automaticallyImplyLeading: false,
iconTheme: IconThemeData(color: Colors.white),
titleSpacing: 0,
// leading: returnIconButtom,
title: Container(
// color: Colors.grey,
width: double.infinity,
height: 180.rpx,
child: Stack(
alignment: Alignment.center,
children: [
/// 居中标题
Text(
'wifi页.标题'.tr,
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Readex Pro',
color: Colors.white,
letterSpacing: 0,
fontSize: 30.rpx,
),
),
/// 左边返回按钮
Positioned(
left: 0,
child: returnIconButtom,
),
Positioned(
right: 20.rpx,
child: CustomCard(
borderRadius: 20.rpx,
onTap: () async {
Get.offAllNamed("/bindDeviceSuccess");
},
colors: [
stringToColor("#45D989"),
stringToColor("#00C1AA"),
],
child: Container(
width: 100.rpx,
height: 60.rpx,
alignment: Alignment.center,
padding: EdgeInsetsDirectional.fromSTEB(
16.rpx, 0, 16.rpx, 0),
child: Text(
'wifi页.跳过'.tr,
style: FlutterFlowTheme.of(context)
.titleSmall
.override(
fontFamily: 'Inter Tight',
color: Colors.white,
letterSpacing: 0.0,
),
),
),
),
),
],
),
),
actions: [],
centerTitle: false,
),
body: SafeArea(
top: true,
child: Padding(
padding: EdgeInsetsDirectional.fromSTEB(30.rpx, 0, 30.rpx, 0),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Padding(
padding:
EdgeInsetsDirectional.fromSTEB(0, 30.rpx, 0, 0),
child: Container(
width: double.infinity,
decoration: BoxDecoration(
color: Color(0xFF242835),
borderRadius: BorderRadius.circular(20.rpx),
),
child: Align(
alignment: AlignmentDirectional(0, 0),
child: Padding(
padding: EdgeInsetsDirectional.fromSTEB(
30.rpx, 30.rpx, 30.rpx, 30.rpx),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
"wifi页.WLAN".tr,
style: TextStyle(
color: themeController.currentColor.sc3,
fontSize:
AppConstants().title_text_fontSize,
),
),
Text(
"wifi页.未连接".tr,
style: TextStyle(
color: themeController.currentColor.sc3,
fontSize:
AppConstants().normal_text_fontSize,
),
),
],
),
),
),
),
),
Padding(
padding: EdgeInsetsDirectional.fromSTEB(
0.rpx, 25.rpx, 0.rpx, 0.rpx),
child: Container(
width: double.infinity,
decoration: BoxDecoration(
color: themeController.currentColor.sc5,
borderRadius: BorderRadius.circular(20.rpx),
),
child: Padding(
padding: EdgeInsetsDirectional.fromSTEB(
30.rpx, 30.rpx, 30.rpx, 30.rpx),
child: Container(
width: double.infinity,
decoration: BoxDecoration(),
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Row(
mainAxisSize: MainAxisSize.max,
children: [
Text(
'可用WLAN',
style: FlutterFlowTheme.of(context)
.bodyMedium
.override(
fontFamily: 'Inter',
fontSize: 30.rpx,
letterSpacing: 0.0,
color: themeController
.currentColor.sc3,
),
),
],
),
Column(
mainAxisSize: MainAxisSize.max,
children: [
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
'6503',
style: FlutterFlowTheme.of(context)
.bodyMedium
.override(
fontFamily: 'Inter',
fontSize: 30.rpx,
letterSpacing: 0.0,
color: themeController
.currentColor.sc3,
),
),
Icon(
Icons.wifi_outlined,
size: 30.rpx,
color: themeController
.currentColor.sc3,
),
],
),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
'6503',
style: FlutterFlowTheme.of(context)
.bodyMedium
.override(
fontFamily: 'Inter',
fontSize: 30.rpx,
letterSpacing: 0.0,
color: themeController
.currentColor.sc3,
),
),
Icon(
Icons.wifi_outlined,
size: 30.rpx,
color: themeController
.currentColor.sc3,
),
],
),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
'6503',
style: FlutterFlowTheme.of(context)
.bodyMedium
.override(
fontFamily: 'Inter',
fontSize: 30.rpx,
letterSpacing: 0.0,
color: themeController
.currentColor.sc3,
),
),
Icon(
Icons.wifi_outlined,
size: 30.rpx,
color: themeController
.currentColor.sc3,
),
],
),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
'6503',
style: FlutterFlowTheme.of(context)
.bodyMedium
.override(
fontFamily: 'Inter',
fontSize: 30.rpx,
letterSpacing: 0.0,
color: themeController
.currentColor.sc3,
),
),
Icon(
Icons.wifi_outlined,
size: 30.rpx,
color: themeController
.currentColor.sc3,
),
],
),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
'6503',
style: FlutterFlowTheme.of(context)
.bodyMedium
.override(
fontFamily: 'Inter',
fontSize: 30.rpx,
letterSpacing: 0.0,
color: themeController
.currentColor.sc3,
),
),
Icon(
Icons.wifi_outlined,
size: 30.rpx,
color: themeController
.currentColor.sc3,
),
],
),
].divide(SizedBox(height: 67.rpx)),
),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.arrow_back,
color: themeController.currentColor.sc3,
size: 30.rpx,
),
Text(
'刷新',
style: FlutterFlowTheme.of(context)
.bodyMedium
.override(
fontFamily: 'Inter',
fontSize: 30.rpx,
letterSpacing: 0.0,
color: themeController
.currentColor.sc3),
),
].divide(SizedBox(width: 26.rpx)),
),
].divide(SizedBox(height: 65.rpx)),
),
),
),
),
),
],
),
),
),
),
),
),
),
);
}
Widget _buildDeviceCard(BuildContext context,
{required String title, required String imageUrl, required String type}) {
return CustomCard(
borderRadius: 20.rpx, // 圆角大小
onTap: () {
if (type != null) {
if (type == '1') {
Get.toNamed("/blueteethDevice");
}
}
},
// colors: [Colors.white.withOpacity(0.06)], // 背景色
colors: [stringToColor("#242835")], // 背景色
child: Container(
width: double.infinity,
height: MediaQuery.sizeOf(context).height * 0.135,
constraints: BoxConstraints(
minHeight: 220.rpx,
),
padding: EdgeInsetsDirectional.fromSTEB(77.rpx, 0, 21.rpx, 0),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
title,
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: const Color(0xFFC2CED7),
fontSize: 30.rpx,
letterSpacing: 0.0,
),
),
ClipRRect(
borderRadius: BorderRadius.circular(8.rpx),
child: Image.asset(
imageUrl,
width: 212.rpx,
height: 168.rpx,
),
),
],
),
),
);
}
getWifiList({int time = 3}) {
// LoadingDialog.show("扫描WIFI列表中...", icon: LoadingDialogIcon.wifi);
try {
var device = widget.bluetoothDevice;
String log = "";
Function logAdd = (l) {
log += l;
};
connectedDeviceProp.receiveLogArr.add(logAdd);
connectedDeviceProp.write3OfString("wscan scan", success: () {
Timer.periodic(const Duration(milliseconds: 1000), (timer) async {
if (timer.tick > 8) {
timer.cancel();
connectedDeviceProp.receiveLogArr.remove(logAdd);
LoadingDialog.hide();
if (time > 0) {
getWifiList(time: time - 1);
}
}
Iterable<RegExpMatch> a = RegExp(
r'ITEM:SSID=([^\t]*)\s*RSSI=(\S*)\s*(,\s*auth\s*=\s*(\S*))?')
.allMatches(log);
if (a.isEmpty == false) {
await Future.delayed(const Duration(milliseconds: 500));
a = RegExp(
r'ITEM:SSID=([^\t]*)\s*RSSI=(\S*)\s*(,\s*auth\s*=\s*(\S*))?')
.allMatches(log);
List arr = [];
for (RegExpMatch one in a) {
arr.add({"name": one[1], "num": one[2], "auth": one[4]});
}
LoadingDialog.hide();
blueteethBindController.model.wifiList = arr;
blueteethBindController.updateAll();
connectedDeviceProp.receiveLogArr.remove(logAdd);
timer.cancel();
checkIsCalibration();
}
});
}, fail: () {
connectedDeviceProp.receiveLogArr.remove(logAdd);
LoadingDialog.hide();
});
} catch (e) {
print(e);
}
}
checkIsCalibration() {
// if (controller.model.bindArr[0] == "" ||
// controller.model.bindArr[0] == null) {
// return;
// }
// if (controller.model.bindArr[2] == "" ||
// controller.model.bindArr[2] == null) {
// return;
// }
// if (controller.model.connectedWifiName == "" ||
// controller.model.connectedWifiName == null) {
// return;
// }
showCustomConfirmAndCancelDialog(context, "是否进行设备校准?", confirmName: "去校准")
.then((d) async {
// if (d == "confirm") {
// await Get.offAndToNamed("/calibration", arguments: [
// controller.model.bindArr[1],
// controller.model.bindArr[2]
// ]);
// Get.find<GlobalController>().getDeviceList();
// }
});
}
}