更新分享
This commit is contained in:
77
lib/component/NullDataComponentWidget.dart
Normal file
77
lib/component/NullDataComponentWidget.dart
Normal file
@@ -0,0 +1,77 @@
|
||||
import 'package:ef/ef.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:vbvs_app/common/util/FitTool.dart';
|
||||
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
|
||||
|
||||
class NullDataWidget extends StatefulWidget {
|
||||
const NullDataWidget({super.key});
|
||||
|
||||
@override
|
||||
State<NullDataWidget> createState() => _TestWidgetState();
|
||||
}
|
||||
|
||||
class _TestWidgetState extends State<NullDataWidget> {
|
||||
final scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
ThemeController themeController = Get.find();
|
||||
return GestureDetector(
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.transparent,
|
||||
key: scaffoldKey,
|
||||
body: SafeArea(
|
||||
top: true,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.transparent,
|
||||
),
|
||||
width: MediaQuery.sizeOf(context).width,
|
||||
height: MediaQuery.sizeOf(context).height * 1,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsetsDirectional.fromSTEB(0, 0.rpx, 0, 0),
|
||||
child: Container(
|
||||
width: 56.rpx,
|
||||
height: 69.rpx,
|
||||
// width: double.infinity,
|
||||
decoration: BoxDecoration(),
|
||||
child: SvgPicture.asset(
|
||||
'assets/img/icon/nulldata.svg',
|
||||
fit: BoxFit.cover,
|
||||
color: themeController.currentColor.sc4,
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
width: MediaQuery.sizeOf(context).width,
|
||||
height: MediaQuery.sizeOf(context).height * 0.04,
|
||||
constraints: BoxConstraints(
|
||||
minHeight: 40,
|
||||
),
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional(0, 0),
|
||||
child: Text(
|
||||
'暂无数据'.tr,
|
||||
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
||||
useGoogleFonts: false,
|
||||
fontFamily: "PingFangSC",
|
||||
letterSpacing: 0.0,
|
||||
fontSize: 26.rpx,
|
||||
color: themeController.currentColor.sc4,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
172
lib/component/home_page/DynamicReportDetailWidget.dart
Normal file
172
lib/component/home_page/DynamicReportDetailWidget.dart
Normal file
@@ -0,0 +1,172 @@
|
||||
import 'package:ef/ef.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:flutterflow_ui/flutterflow_ui.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/component/home_page/SleepDataModuleWidget.dart';
|
||||
import 'package:vbvs_app/component/home_page/SleepDateWidget.dart';
|
||||
import 'package:vbvs_app/component/tool/ClickableContainer.dart';
|
||||
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
|
||||
|
||||
class DynamicReportDetailWidget extends StatelessWidget {
|
||||
final List<SleepDateWidget> sleepDateWidgets;
|
||||
final List<SleepDataModuleWidget> sleepDataModuleWidgets;
|
||||
final ThemeController themeController = Get.find();
|
||||
final Map targetDevice;
|
||||
|
||||
DynamicReportDetailWidget({
|
||||
required this.sleepDateWidgets,
|
||||
required this.sleepDataModuleWidgets,
|
||||
required this.targetDevice,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: EdgeInsetsDirectional.fromSTEB(0, 25.rpx, 0, 25.rpx),
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: themeController.currentColor.sc5,
|
||||
borderRadius:
|
||||
BorderRadius.circular(AppConstants().normal_container_radius),
|
||||
),
|
||||
child: Padding(
|
||||
padding:
|
||||
EdgeInsetsDirectional.fromSTEB(30.rpx, 30.rpx, 30.rpx, 30.rpx),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
_buildHeader(context),
|
||||
_buildSleepDateWidgets(),
|
||||
SizedBox(height: 20.rpx),
|
||||
_buildSleepDataModuleWidgets(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHeader(BuildContext context) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'${targetDevice['person']?['name'] == null ? '未命名'.tr : targetDevice['person']['name']}',
|
||||
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 30.rpx,
|
||||
letterSpacing: 0.0,
|
||||
color: themeController.currentColor.sc3,
|
||||
),
|
||||
),
|
||||
ClickableContainer(
|
||||
backgroundColor: Colors.transparent,
|
||||
highlightColor: themeController.currentColor.sc3,
|
||||
borderRadius: 0,
|
||||
padding: EdgeInsets.zero,
|
||||
onTap: () {
|
||||
String mac = targetDevice['mac'];
|
||||
List<SleepDateWidget> selectedWidgets = sleepDateWidgets
|
||||
.where(
|
||||
(widget) => widget.isSelected == true,
|
||||
)
|
||||
.toList();
|
||||
DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(
|
||||
int.parse(selectedWidgets[0].time!));
|
||||
String time = MyUtils.formatBindTime(dateTime);
|
||||
String sleepReportUrl =
|
||||
"${ServiceConstant.sleep_report_url}?mac=${mac}&token=${ServiceConstant.sleep_token}&date=${time}";
|
||||
Get.toNamed("/sleepReportPage", arguments: sleepReportUrl);
|
||||
},
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Text(
|
||||
'首页.报告详情'.tr,
|
||||
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 26.rpx,
|
||||
letterSpacing: 0.0,
|
||||
color: themeController.currentColor.sc3,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsetsDirectional.fromSTEB(0, 6.rpx, 0, 0.rpx),
|
||||
child: SvgPicture.asset(
|
||||
'assets/img/icon/arrow_right.svg',
|
||||
width: 14.rpx,
|
||||
height: 14.rpx,
|
||||
color: themeController.currentColor.sc3,
|
||||
),
|
||||
),
|
||||
].divide(SizedBox(width: 22.rpx)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSleepDateWidgets() {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(),
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: sleepDateWidgets
|
||||
.map((widget) => widget)
|
||||
.toList()
|
||||
.divide(SizedBox(width: 20.rpx)),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSleepDataModuleWidgets() {
|
||||
// bool hasData = sleepDataModuleWidgets.any((w) {
|
||||
// final data = w.data;
|
||||
// return data['state'] != null &&
|
||||
// data['state'].toString().trim().isNotEmpty;
|
||||
// });
|
||||
bool hasData = sleepDataModuleWidgets.length > 0;
|
||||
|
||||
if (!hasData) {
|
||||
return Container(
|
||||
height: 100.rpx,
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'暂无数据'.tr,
|
||||
style: FlutterFlowTheme.of(Get.context!).bodyMedium.override(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 28.rpx,
|
||||
color: themeController.currentColor.sc3,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: sleepDataModuleWidgets
|
||||
.map((widget) => widget)
|
||||
.toList()
|
||||
.divide(SizedBox(width: 14.rpx)),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,16 @@
|
||||
import 'package:ef/base/widget/flutterflow/FlutterFlowTheme.dart';
|
||||
import 'package:ef/ef.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutterflow_ui/flutterflow_ui.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/ClickableContainer.dart';
|
||||
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
|
||||
|
||||
class SleepDataModuleWidget extends StatefulWidget {
|
||||
const SleepDataModuleWidget({super.key});
|
||||
final Map<String, dynamic> data;
|
||||
|
||||
const SleepDataModuleWidget({super.key, required this.data});
|
||||
|
||||
@override
|
||||
State<SleepDataModuleWidget> createState() => _SleepDataModuleWidgetState();
|
||||
@@ -33,111 +35,137 @@ class _SleepDataModuleWidgetState extends State<SleepDataModuleWidget> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
ThemeController themeController = Get.find();
|
||||
return Container(
|
||||
width: MediaQuery.sizeOf(context).width * 0.27,
|
||||
constraints: BoxConstraints(
|
||||
minWidth: 200.rpx,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: themeController.currentColor.sc5,
|
||||
borderRadius: BorderRadius.circular(20.rpx),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsetsDirectional.fromSTEB(18.rpx, 18.rpx, 18.rpx, 22.rpx),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'离床次数',
|
||||
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 26.rpx,
|
||||
letterSpacing: 0.0,
|
||||
color: themeController.currentColor.sc3,
|
||||
return ClickableContainer(
|
||||
backgroundColor: themeController.currentColor.sc5,
|
||||
highlightColor: themeController.currentColor.sc3,
|
||||
borderRadius: 20.rpx,
|
||||
padding: EdgeInsetsDirectional.fromSTEB(18.rpx, 18.rpx, 18.rpx, 22.rpx),
|
||||
onTap: () {
|
||||
print('点击了离床次数卡片');
|
||||
},
|
||||
child: Container(
|
||||
width: MediaQuery.sizeOf(context).width * 0.27,
|
||||
constraints: BoxConstraints(
|
||||
minWidth: 200.rpx,
|
||||
minHeight: 161.rpx,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Text(
|
||||
'${widget.data['name']}',
|
||||
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 26.rpx,
|
||||
letterSpacing: 0.0,
|
||||
color: themeController.currentColor.sc3,
|
||||
),
|
||||
),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
'${widget.data['value']}',
|
||||
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 40.rpx,
|
||||
letterSpacing: 0.0,
|
||||
color: themeController.currentColor.sc3,
|
||||
),
|
||||
),
|
||||
),
|
||||
// SizedBox(
|
||||
// height: 21.rpx,
|
||||
// ),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
'4',
|
||||
Padding(
|
||||
padding: EdgeInsetsDirectional.fromSTEB(0, 0, 0, 10.rpx),
|
||||
child: Text(
|
||||
'${widget.data['unit'] ?? ''}',
|
||||
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 40.rpx,
|
||||
fontSize: AppConstants().small_text_fontSize,
|
||||
letterSpacing: 0.0,
|
||||
color: themeController.currentColor.sc3,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsetsDirectional.fromSTEB(
|
||||
0.rpx, 0, 0.rpx, 10.rpx),
|
||||
child: Text(
|
||||
'次',
|
||||
style: FlutterFlowTheme.of(context)
|
||||
.bodyMedium
|
||||
.override(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: AppConstants().small_text_fontSize,
|
||||
letterSpacing: 0.0,
|
||||
color: themeController.currentColor.sc3,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
// Container(
|
||||
// width: MediaQuery.sizeOf(context).width * 0.07,
|
||||
// height: MediaQuery.sizeOf(context).height * 0.014,
|
||||
// constraints: BoxConstraints(
|
||||
// minWidth: 43.rpx,
|
||||
// minHeight: 36.rpx,
|
||||
// ),
|
||||
// child: FFButtonWidget(
|
||||
// onPressed: () {
|
||||
// print('Button pressed ...');
|
||||
// },
|
||||
// // text: '${widget.data['level']}',
|
||||
// text: '${widget.data['level']}',
|
||||
// options: FFButtonOptions(
|
||||
// height: 40.rpx,
|
||||
// padding: EdgeInsets.zero,
|
||||
// // color: themeController.currentColor.sc14,
|
||||
// color: stringToColor('${widget.data['color']}'),
|
||||
// textStyle:
|
||||
// FlutterFlowTheme.of(context).titleSmall.override(
|
||||
// fontFamily: 'Inter Tight',
|
||||
// color: themeController.currentColor.sc3,
|
||||
// // color: stringToColor('${widget.data['color']}'),
|
||||
// letterSpacing: 0.0,
|
||||
// fontSize: 15.rpx,
|
||||
// ),
|
||||
// elevation: 0,
|
||||
// borderRadius: BorderRadius.circular(8.rpx),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
|
||||
ClickableContainer(
|
||||
backgroundColor: stringToColor('${widget.data['color']}'),
|
||||
highlightColor: themeController.currentColor.sc3,
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 0.rpx,
|
||||
vertical: 0.rpx,
|
||||
),
|
||||
Container(
|
||||
width: MediaQuery.sizeOf(context).width * 0.07,
|
||||
height: MediaQuery.sizeOf(context).height * 0.014,
|
||||
borderRadius: 8.rpx,
|
||||
onTap: () {
|
||||
print('Button pressed ...');
|
||||
},
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
constraints: BoxConstraints(
|
||||
minWidth: 43.rpx,
|
||||
minHeight: 36.rpx,
|
||||
),
|
||||
decoration: BoxDecoration(),
|
||||
child: FFButtonWidget(
|
||||
onPressed: () {
|
||||
print('Button pressed ...');
|
||||
},
|
||||
text: '异常',
|
||||
options: FFButtonOptions(
|
||||
height: 40.rpx,
|
||||
padding:
|
||||
EdgeInsetsDirectional.fromSTEB(0.rpx, 0, 0.rpx, 0),
|
||||
color: themeController.currentColor.sc14,
|
||||
textStyle:
|
||||
FlutterFlowTheme.of(context).titleSmall.override(
|
||||
fontFamily: 'Inter Tight',
|
||||
color: themeController.currentColor.sc3,
|
||||
letterSpacing: 0.0,
|
||||
fontSize: 15.rpx,
|
||||
),
|
||||
elevation: 0,
|
||||
borderRadius: BorderRadius.circular(8.rpx),
|
||||
),
|
||||
child: Text(
|
||||
'${widget.data['level']}',
|
||||
style: FlutterFlowTheme.of(context).titleSmall.override(
|
||||
fontFamily: 'Inter Tight',
|
||||
color: themeController.currentColor.sc3,
|
||||
letterSpacing: 0.0,
|
||||
fontSize: 15.rpx,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
'正常值:0~2',
|
||||
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
||||
),
|
||||
].divide(SizedBox(width: 0.rpx)),
|
||||
),
|
||||
Text(
|
||||
'${widget.data['range']}',
|
||||
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: AppConstants().small_text_fontSize,
|
||||
letterSpacing: 0.0,
|
||||
color: themeController.currentColor.sc4),
|
||||
),
|
||||
],
|
||||
),
|
||||
color: themeController.currentColor.sc4,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -6,10 +6,28 @@ 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/ClickableContainer.dart';
|
||||
import 'package:vbvs_app/controller/device/body_device_controller.dart';
|
||||
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
|
||||
|
||||
class SleepDateWidget extends StatefulWidget {
|
||||
const SleepDateWidget({super.key});
|
||||
final String? mac;
|
||||
final String? time; // 必传:日期,例如 "07/15"
|
||||
final DateTime date; // 必传:日期,例如 "07/15"
|
||||
final String? score; // 可选:分数,默认为 "--"
|
||||
final String? comment; // 可选:评价,默认为 "暂无".tr
|
||||
final Color? textColor; // 可选:文字颜色,默认为灰色
|
||||
final bool? isSelected; // 是否选中
|
||||
|
||||
const SleepDateWidget({
|
||||
super.key,
|
||||
this.mac,
|
||||
this.time,
|
||||
required this.date,
|
||||
this.score = '--',
|
||||
this.comment = '暂无',
|
||||
this.textColor,
|
||||
this.isSelected = false, // 新增参数,默认不选中
|
||||
});
|
||||
|
||||
@override
|
||||
State<SleepDateWidget> createState() => _SleepDateWidgetState();
|
||||
@@ -19,14 +37,35 @@ class _SleepDateWidgetState extends State<SleepDateWidget> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
ThemeController themeController = Get.find();
|
||||
BodyDeviceController bodyDeviceController = Get.find();
|
||||
String week = MyUtils.formatDateTimeWeek(widget.date);
|
||||
String day = MyUtils.formatDateTimeDay(widget.date);
|
||||
|
||||
// 选中时背景色为黑色,否则为透明
|
||||
Color backgroundColor =
|
||||
widget.isSelected == true ? Colors.black : Colors.transparent;
|
||||
|
||||
return ClickableContainer(
|
||||
backgroundColor: Colors.transparent, // 原 BoxDecoration 为空
|
||||
highlightColor:
|
||||
themeController.currentColor.sc3.withOpacity(0.1), // 自定义点击波纹颜色
|
||||
borderRadius: AppConstants().normal_container_radius, // 原来没设置圆角
|
||||
backgroundColor: backgroundColor,
|
||||
// highlightColor: themeController.currentColor.sc3.withOpacity(0.1),
|
||||
highlightColor: Colors.transparent,
|
||||
borderRadius: AppConstants().normal_container_radius,
|
||||
padding: EdgeInsets.zero,
|
||||
onTap: () {
|
||||
print("今日评分卡片点击");
|
||||
final mac = widget.mac;
|
||||
final time = widget.time;
|
||||
|
||||
if (bodyDeviceController.sleepReportData.value.containsKey(mac)) {
|
||||
final list = bodyDeviceController.sleepReportData.value[mac];
|
||||
|
||||
for (var item in list!) {
|
||||
item['selected'] = (item['time'] == time);
|
||||
}
|
||||
bodyDeviceController.sleepReportData.value = {
|
||||
...bodyDeviceController.sleepReportData.value,
|
||||
};
|
||||
bodyDeviceController.updateAll();
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
width: MediaQuery.sizeOf(context).width * 0.19,
|
||||
@@ -36,54 +75,55 @@ class _SleepDateWidgetState extends State<SleepDateWidget> {
|
||||
child: Padding(
|
||||
padding:
|
||||
EdgeInsetsDirectional.fromSTEB(10.rpx, 25.rpx, 10.rpx, 22.rpx),
|
||||
child: Container(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsetsDirectional.fromSTEB(0, 0, 0, 14.rpx),
|
||||
child: Text(
|
||||
'今日',
|
||||
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: AppConstants().title_text_fontSize,
|
||||
letterSpacing: 0.0,
|
||||
color: themeController.currentColor.sc3,
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsetsDirectional.fromSTEB(0, 0, 0, 33.rpx),
|
||||
child: Text(
|
||||
'07/15',
|
||||
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 20.rpx,
|
||||
letterSpacing: 0.0,
|
||||
color: themeController.currentColor.sc3,
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsetsDirectional.fromSTEB(0, 0, 0, 16.rpx),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
'70',
|
||||
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 48.rpx,
|
||||
letterSpacing: 0.0,
|
||||
color: stringToColor("#00C1AA")),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsetsDirectional.fromSTEB(0, 0, 0, 14.rpx),
|
||||
child: Text(
|
||||
'${week}',
|
||||
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: AppConstants().title_text_fontSize,
|
||||
letterSpacing: 0.0,
|
||||
color: themeController.currentColor.sc3,
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsetsDirectional.fromSTEB(0, 0, 0, 33.rpx),
|
||||
child: Text(
|
||||
'${day}',
|
||||
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 20.rpx,
|
||||
letterSpacing: 0.0,
|
||||
color: themeController.currentColor.sc3,
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsetsDirectional.fromSTEB(0, 0, 0, 16.rpx),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
(widget.score?.isEmpty ?? true) ? '--' : widget.score!,
|
||||
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 48.rpx,
|
||||
letterSpacing: 0.0,
|
||||
color: widget.textColor ??
|
||||
themeController.currentColor.sc4),
|
||||
),
|
||||
if ((widget.score?.trim().isNotEmpty ?? false))
|
||||
Padding(
|
||||
padding:
|
||||
EdgeInsetsDirectional.fromSTEB(0, 16.rpx, 0, 0.rpx),
|
||||
child: Text(
|
||||
'分',
|
||||
'分'.tr,
|
||||
style: FlutterFlowTheme.of(context)
|
||||
.bodyMedium
|
||||
.override(
|
||||
@@ -94,40 +134,40 @@ class _SleepDateWidgetState extends State<SleepDateWidget> {
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
Container(
|
||||
width: 0.2.rpx,
|
||||
height: 2.4.rpx,
|
||||
constraints: BoxConstraints(
|
||||
minWidth: 123.rpx,
|
||||
minHeight: 47.rpx,
|
||||
),
|
||||
child: FFButtonWidget(
|
||||
onPressed: () {
|
||||
print('合格按钮点击');
|
||||
},
|
||||
text: (widget.comment?.trim().isEmpty ?? true)
|
||||
? '暂无'.tr
|
||||
: widget.comment!,
|
||||
options: FFButtonOptions(
|
||||
height: 40.rpx,
|
||||
padding:
|
||||
EdgeInsetsDirectional.fromSTEB(16.rpx, 0, 16.rpx, 0),
|
||||
iconPadding: EdgeInsetsDirectional.fromSTEB(0, 0, 0, 0),
|
||||
color: widget.textColor ?? themeController.currentColor.sc4,
|
||||
textStyle: FlutterFlowTheme.of(context).titleSmall.override(
|
||||
fontFamily: 'Inter Tight',
|
||||
color: themeController.currentColor.sc3,
|
||||
letterSpacing: 0.0,
|
||||
),
|
||||
elevation: 0,
|
||||
borderRadius: BorderRadius.circular(50.rpx),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
width: 0.2.rpx,
|
||||
height: 2.4.rpx,
|
||||
constraints: BoxConstraints(
|
||||
minWidth: 123.rpx,
|
||||
minHeight: 47.rpx,
|
||||
),
|
||||
child: FFButtonWidget(
|
||||
onPressed: () {
|
||||
print('合格按钮点击');
|
||||
},
|
||||
text: '合格',
|
||||
options: FFButtonOptions(
|
||||
height: 40.rpx,
|
||||
padding:
|
||||
EdgeInsetsDirectional.fromSTEB(16.rpx, 0, 16.rpx, 0),
|
||||
iconPadding: EdgeInsetsDirectional.fromSTEB(0, 0, 0, 0),
|
||||
color: stringToColor("#00C1AA"),
|
||||
textStyle:
|
||||
FlutterFlowTheme.of(context).titleSmall.override(
|
||||
fontFamily: 'Inter Tight',
|
||||
color: themeController.currentColor.sc3,
|
||||
letterSpacing: 0.0,
|
||||
),
|
||||
elevation: 0,
|
||||
borderRadius: BorderRadius.circular(50.rpx),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:vbvs_app/common/util/FitTool.dart';
|
||||
|
||||
class CustomCard extends StatefulWidget {
|
||||
final double borderRadius; // 圆角
|
||||
@@ -15,7 +16,7 @@ class CustomCard extends StatefulWidget {
|
||||
required this.colors,
|
||||
required this.child,
|
||||
this.enableAnimation = true, // 默认启用动画效果
|
||||
this.enableGradient = true, // 默认启用渐变效果
|
||||
this.enableGradient = true, // 默认启用渐变效果
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
@@ -25,36 +26,19 @@ class CustomCard extends StatefulWidget {
|
||||
class _CustomCardState extends State<CustomCard>
|
||||
with SingleTickerProviderStateMixin {
|
||||
double _scale = 1.0;
|
||||
final Duration _animationDuration = Duration(milliseconds: 50);
|
||||
final GlobalKey _inkKey = GlobalKey();
|
||||
final Duration _animationDuration = const Duration(milliseconds: 50);
|
||||
|
||||
Future<void> _handleTap(TapDownDetails details) async {
|
||||
setState(() {
|
||||
_scale = 0.95;
|
||||
});
|
||||
Future<void> _handleTap() async {
|
||||
if (widget.enableAnimation) {
|
||||
setState(() {
|
||||
_scale = 0.95;
|
||||
});
|
||||
|
||||
await Future.delayed(_animationDuration);
|
||||
await Future.delayed(_animationDuration);
|
||||
|
||||
setState(() {
|
||||
_scale = 1.0;
|
||||
});
|
||||
|
||||
await Future.delayed(_animationDuration);
|
||||
|
||||
// 手动触发水波纹
|
||||
final RenderBox? box =
|
||||
_inkKey.currentContext?.findRenderObject() as RenderBox?;
|
||||
if (box != null) {
|
||||
final Offset localPosition = box.globalToLocal(details.globalPosition);
|
||||
InkRipple.splashFactory.create(
|
||||
controller: Material.of(_inkKey.currentContext!)!,
|
||||
referenceBox: box,
|
||||
position: localPosition,
|
||||
color: widget.colors.first.withOpacity(0.2),
|
||||
containedInkWell: true,
|
||||
borderRadius: BorderRadius.circular(widget.borderRadius),
|
||||
textDirection: Directionality.of(context),
|
||||
);
|
||||
setState(() {
|
||||
_scale = 1.0;
|
||||
});
|
||||
}
|
||||
|
||||
widget.onTap();
|
||||
@@ -62,51 +46,44 @@ class _CustomCardState extends State<CustomCard>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bool isGradient = widget.enableGradient && widget.colors.length > 1; // 只有启用渐变时,才使用渐变
|
||||
final bool isGradient = widget.enableGradient && widget.colors.length > 1;
|
||||
final Color baseColor = widget.colors.first;
|
||||
|
||||
return Material(
|
||||
color: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(widget.borderRadius),
|
||||
child: GestureDetector(
|
||||
onTapDown: _handleTap,
|
||||
behavior: HitTestBehavior.translucent, // 关键:让空白区域也能点击
|
||||
child: widget.enableAnimation // 判断是否启用动画
|
||||
child: InkWell(
|
||||
onTap: _handleTap,
|
||||
borderRadius: BorderRadius.circular(widget.borderRadius),
|
||||
splashColor: widget.colors.first.withOpacity(0.2),
|
||||
child: widget.enableAnimation
|
||||
? AnimatedScale(
|
||||
scale: _scale,
|
||||
duration: _animationDuration,
|
||||
curve: Curves.easeInOut,
|
||||
child: Ink(
|
||||
key: _inkKey,
|
||||
decoration: BoxDecoration(
|
||||
color: isGradient ? null : baseColor,
|
||||
gradient: isGradient
|
||||
? LinearGradient(
|
||||
colors: widget.colors,
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
)
|
||||
: null,
|
||||
borderRadius: BorderRadius.circular(widget.borderRadius),
|
||||
),
|
||||
child: widget.child,
|
||||
),
|
||||
child: _buildContent(isGradient, baseColor),
|
||||
)
|
||||
: Ink(
|
||||
key: _inkKey,
|
||||
decoration: BoxDecoration(
|
||||
color: isGradient ? null : baseColor,
|
||||
gradient: isGradient
|
||||
? LinearGradient(
|
||||
colors: widget.colors,
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
)
|
||||
: null,
|
||||
borderRadius: BorderRadius.circular(widget.borderRadius),
|
||||
),
|
||||
child: widget.child,
|
||||
),
|
||||
: _buildContent(isGradient, baseColor),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContent(bool isGradient, Color baseColor) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: isGradient ? null : baseColor,
|
||||
gradient: isGradient
|
||||
? LinearGradient(
|
||||
colors: widget.colors,
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
)
|
||||
: null,
|
||||
borderRadius: BorderRadius.circular(widget.borderRadius),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.fromLTRB(0.rpx, 0.rpx, 0.rpx, 5.rpx),
|
||||
child: widget.child,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
79
lib/component/tool/SelectableTagButton.dart
Normal file
79
lib/component/tool/SelectableTagButton.dart
Normal file
@@ -0,0 +1,79 @@
|
||||
import 'package:ef/ef.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:vbvs_app/common/color/appConstants.dart';
|
||||
import 'package:vbvs_app/common/util/FitTool.dart';
|
||||
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
|
||||
|
||||
import 'CustomCard.dart';
|
||||
|
||||
class SelectableTagButton extends StatelessWidget {
|
||||
final String label;
|
||||
final bool selected;
|
||||
final VoidCallback onTap;
|
||||
final double minWidth; // 最小宽度,单位:dp(会转 rpx)
|
||||
final double maxWidth; // 最大宽度,单位:dp(会转 rpx)
|
||||
|
||||
ThemeController themeController = Get.find();
|
||||
|
||||
SelectableTagButton({
|
||||
Key? key,
|
||||
required this.label,
|
||||
required this.selected,
|
||||
required this.onTap,
|
||||
this.minWidth = 132, // 默认最小宽度
|
||||
this.maxWidth = 500, // 默认最大宽度
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final double minWidthRpx = minWidth.rpx;
|
||||
final double maxWidthRpx = maxWidth.rpx;
|
||||
final double horizontalPadding = 28.rpx * 2; // 左右各 28,总 56
|
||||
// 估算文本宽度:每个字符按 14.rpx 字号估一个宽度
|
||||
final double estimatedTextWidth = label.length * 33.rpx;
|
||||
|
||||
// 总宽度 = 文本宽度 + padding
|
||||
final double totalWidth = estimatedTextWidth + horizontalPadding;
|
||||
|
||||
// 限制在 min 和 max 之间
|
||||
final double constrainedWidth = totalWidth.clamp(minWidthRpx, maxWidthRpx);
|
||||
|
||||
return CustomCard(
|
||||
onTap: onTap,
|
||||
borderRadius: AppConstants().normal_container_radius,
|
||||
colors: selected
|
||||
? [themeController.currentColor.sc1, themeController.currentColor.sc2]
|
||||
: [Colors.transparent],
|
||||
// colors: [Colors.transparent],
|
||||
enableGradient: true,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
border: selected
|
||||
? null
|
||||
: Border.all(
|
||||
color: themeController.currentColor.sc4,
|
||||
width: 1.rpx,
|
||||
), // 未选中时无边框
|
||||
borderRadius: BorderRadius.circular(12.0), // 如果需要圆角
|
||||
),
|
||||
padding: EdgeInsets.symmetric(horizontal: 28.rpx),
|
||||
constraints: BoxConstraints(
|
||||
minHeight: 61.rpx,
|
||||
maxWidth: constrainedWidth,
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
label,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
color: selected
|
||||
? themeController.currentColor.sc3
|
||||
: themeController.currentColor.sc4,
|
||||
fontSize: AppConstants().normal_text_fontSize, // 字体也用 rpx 控制
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
130
lib/component/tool/TopSlideNotification.dart
Normal file
130
lib/component/tool/TopSlideNotification.dart
Normal file
@@ -0,0 +1,130 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:vbvs_app/common/util/FitTool.dart';
|
||||
import 'package:vbvs_app/common/util/MyUtils.dart';
|
||||
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
|
||||
|
||||
class TopSlideNotification extends StatefulWidget {
|
||||
final String text;
|
||||
double? fontSize = 26.rpx;
|
||||
Color? textColor;
|
||||
double? slideOffset = 200;
|
||||
final Duration duration;
|
||||
|
||||
TopSlideNotification({
|
||||
super.key,
|
||||
this.text = '操作成功!',
|
||||
this.fontSize,
|
||||
this.textColor,
|
||||
this.slideOffset,
|
||||
this.duration = const Duration(seconds: 2),
|
||||
});
|
||||
|
||||
@override
|
||||
State<TopSlideNotification> createState() => _TopSlideNotificationState();
|
||||
|
||||
/// 工具方法:调用时直接加进 Overlay 上
|
||||
static void show(
|
||||
BuildContext context, {
|
||||
String text = '操作成功!',
|
||||
double fontSize = 16,
|
||||
Color? textColor,
|
||||
double slideOffset = 300.0,
|
||||
Duration duration = const Duration(seconds: 2),
|
||||
}) {
|
||||
final overlay = Overlay.of(context);
|
||||
final entry = OverlayEntry(
|
||||
builder: (_) => TopSlideNotification(
|
||||
text: text,
|
||||
fontSize: fontSize,
|
||||
textColor: textColor,
|
||||
slideOffset: slideOffset,
|
||||
duration: duration,
|
||||
),
|
||||
);
|
||||
overlay.insert(entry);
|
||||
|
||||
Future.delayed(duration + const Duration(milliseconds: 500), () {
|
||||
entry.remove();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class _TopSlideNotificationState extends State<TopSlideNotification>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late AnimationController _controller;
|
||||
late Animation<Offset> _animation;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_controller = AnimationController(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
vsync: this,
|
||||
);
|
||||
|
||||
SchedulerBinding.instance.addPostFrameCallback((_) async {
|
||||
await _controller.forward();
|
||||
await Future.delayed(widget.duration);
|
||||
await _controller.reverse();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
|
||||
final screenHeight = MediaQuery.of(context).size.height;
|
||||
final offsetValue = widget.slideOffset! / screenHeight;
|
||||
|
||||
_animation = Tween<Offset>(
|
||||
begin: const Offset(0, -1),
|
||||
end: Offset(0, offsetValue),
|
||||
).animate(CurvedAnimation(
|
||||
parent: _controller,
|
||||
curve: Curves.easeOut,
|
||||
reverseCurve: Curves.easeIn,
|
||||
));
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Color get _textColor {
|
||||
return widget.textColor ?? Get.find<ThemeController>().currentColor.sc2;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Positioned(
|
||||
top: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: SlideTransition(
|
||||
position: _animation,
|
||||
child: Material(
|
||||
color: stringToColor("#000000").withOpacity(0.8),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 20.0),
|
||||
child: Container(
|
||||
// color: Colors.red,
|
||||
child: Text(
|
||||
widget.text,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: widget.fontSize,
|
||||
color: _textColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
51
lib/component/tool/WebViewWidget.dart
Normal file
51
lib/component/tool/WebViewWidget.dart
Normal file
@@ -0,0 +1,51 @@
|
||||
// import 'package:flutter/material.dart';
|
||||
// import 'package:webview_flutter/webview_flutter.dart';
|
||||
|
||||
// class WebViewWidget extends StatefulWidget {
|
||||
// final String url;
|
||||
// const WebViewWidget({Key? key, required this.url}) : super(key: key);
|
||||
|
||||
// @override
|
||||
// _WebViewWidgetState createState() => _WebViewWidgetState();
|
||||
// }
|
||||
|
||||
// class _WebViewWidgetState extends State<WebViewWidget> {
|
||||
// late WebViewController _webViewController;
|
||||
|
||||
// @override
|
||||
// void initState() {
|
||||
// super.initState();
|
||||
// // 初始化 WebView 控件
|
||||
// WebView.platform = SurfaceAndroidWebView();
|
||||
// }
|
||||
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return Scaffold(
|
||||
// appBar: AppBar(
|
||||
// title: Text('WebView'),
|
||||
// ),
|
||||
// body: WebView(
|
||||
// initialUrl: widget.url, // 设置要打开的网页地址
|
||||
// javascriptMode: JavascriptMode.unrestricted, // 启用 JavaScript
|
||||
// onWebViewCreated: (WebViewController webViewController) {
|
||||
// _webViewController = webViewController;
|
||||
// },
|
||||
// onPageStarted: (String url) {
|
||||
// print("页面开始加载:$url");
|
||||
// },
|
||||
// onPageFinished: (String url) {
|
||||
// print("页面加载完成:$url");
|
||||
// },
|
||||
// navigationDelegate: (NavigationRequest request) {
|
||||
// if (request.url.startsWith('https://www.google.com/')) {
|
||||
// print('拦截了URL请求: ${request.url}');
|
||||
// return NavigationDecision.prevent; // 拦截特定的请求
|
||||
// }
|
||||
// return NavigationDecision.navigate;
|
||||
// },
|
||||
// gestureNavigationEnabled: true, // 启用手势返回
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
166
lib/component/tool/cmd.dart
Normal file
166
lib/component/tool/cmd.dart
Normal file
@@ -0,0 +1,166 @@
|
||||
//蓝牙指令
|
||||
|
||||
// wifi列表指令
|
||||
import 'package:EasyDartModule/EasyDartModule.dart' as edm;
|
||||
import 'package:easydevice/src/app/thapp.dart';
|
||||
import 'package:vbvs_app/common/util/DailyLogUtils.dart';
|
||||
|
||||
getWifiList(THapp tHapp) async {
|
||||
try {
|
||||
edm.EasyDartModule.logger.info("发送请求网络列表指令");
|
||||
DailyLogUtils.writeLog("发送请求网络列表指令");
|
||||
List data = [];
|
||||
var wifilist = await tHapp.send("wscan scan", true, (log) {
|
||||
print("[bles]${log.log}");
|
||||
if (log.log.contains("SCAN RESULT OVER!")) {
|
||||
final wifiList = <Map<String, dynamic>>[];
|
||||
final items = log.log.split('[wifi]: SCAN RESULT ITEM:');
|
||||
final reg =
|
||||
RegExp(r'SSID=([^\t\r\n]+)\s+RSSI=(-?\d+)\s*,\s*auth\s*=\s*(\d+)');
|
||||
|
||||
for (var item in items) {
|
||||
final match = reg.firstMatch(item);
|
||||
if (match != null) {
|
||||
wifiList.add({
|
||||
'ssid': match.group(1),
|
||||
'rssi': int.parse(match.group(2)!),
|
||||
'auth': int.parse(match.group(3)!),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
print('解析得到 Wi-Fi 列表: $wifiList');
|
||||
if (wifiList.length != 0) {
|
||||
log.result = wifiList;
|
||||
data = wifiList;
|
||||
log.over = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}, 10);
|
||||
|
||||
return wifilist;
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
getWifiStatus(THapp tHapp) async {
|
||||
edm.EasyDartModule.logger.info("发送请求设备网络状态指令");
|
||||
DailyLogUtils.writeLog("发送请求设备网络状态指令");
|
||||
var result = await tHapp.send(
|
||||
"wl show",
|
||||
true,
|
||||
(ss) {
|
||||
var log = ss.log;
|
||||
final match = RegExp(r'status=([^\s]+)').firstMatch(log);
|
||||
final status = match?.group(1);
|
||||
if (status != null) {
|
||||
print('提取到的 status: $status');
|
||||
if (status == 'connect') {
|
||||
ss.result = true;
|
||||
ss.over = true;
|
||||
return true;
|
||||
} else {
|
||||
ss.result = false;
|
||||
ss.over = true;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<bool> sendWifiSetting(wifiItem, String password, THapp tHapp) async {
|
||||
try {
|
||||
edm.EasyDartModule.logger.info("发送wifi配置指令");
|
||||
DailyLogUtils.writeLog("发送wifi配置指令->");
|
||||
String cmd = "vtouch save update -a -i .wifi.sta.auth=${wifiItem['auth']} "
|
||||
".wifi.sta.ssid=${wifiItem['ssid']} .wifi.sta.pwd=$password";
|
||||
final success = await tHapp.send(cmd, true, (log) {
|
||||
if (log.log.contains("update parm is successful")) {
|
||||
print("[wifi456]:" + log.log);
|
||||
edm.EasyDartModule.logger.info("WiFi配置成功-》log:$log");
|
||||
DailyLogUtils.writeLog("WiFi配置成功->log:$log");
|
||||
log.result = true;
|
||||
log.over = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}, 10);
|
||||
|
||||
if (!success) {
|
||||
edm.EasyDartModule.logger.error("WiFi配置超时或失败");
|
||||
DailyLogUtils.writeLog("WiFi配置超时或失败");
|
||||
}
|
||||
return success;
|
||||
} catch (e) {
|
||||
edm.EasyDartModule.logger.error("发送wifi配置指令异常: ${e.toString()}");
|
||||
DailyLogUtils.writeLog("发送wifi配置指令异常-> ${e.toString()}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
getDeviceWifiStatus(THapp tHapp) async {
|
||||
edm.EasyDartModule.logger.info("发送请求设备已配置网络状态指令");
|
||||
DailyLogUtils.writeLog("发送请求设备已配置网络状态指令");
|
||||
|
||||
var result = await tHapp.send(
|
||||
"at+system info",
|
||||
true,
|
||||
(ss) {
|
||||
var log = ss.log;
|
||||
|
||||
// 匹配设备状态
|
||||
final statusMatch = RegExp(r'status=([^\s]+)').firstMatch(log);
|
||||
final status = statusMatch?.group(1);
|
||||
if (status != null) {
|
||||
print('提取到的 status: $status');
|
||||
|
||||
// 如果设备连接状态是 "connect",继续检测
|
||||
if (status == 'connect') {
|
||||
ss.result = true;
|
||||
ss.over = true;
|
||||
|
||||
// 匹配 Wi-Fi 连接信息
|
||||
final wifiInfoMatch = RegExp(
|
||||
r'WIFI CONNECTED INFO:SSID=([^\s]+),RSSI=([-0-9]+),AUTH=([0-9]+),CH=([0-9]+),BSSID=([A-F0-9]+)')
|
||||
.firstMatch(log);
|
||||
if (wifiInfoMatch != null) {
|
||||
final ssid = wifiInfoMatch.group(1);
|
||||
final rssi = wifiInfoMatch.group(2);
|
||||
final auth = wifiInfoMatch.group(3);
|
||||
final ch = wifiInfoMatch.group(4);
|
||||
final bssid = wifiInfoMatch.group(5);
|
||||
|
||||
// 打印并返回 Wi-Fi 信息
|
||||
print(
|
||||
'Wi-Fi 信息: SSID=$ssid, RSSI=$rssi, AUTH=$auth, CH=$ch, BSSID=$bssid');
|
||||
|
||||
// 停止监听并返回信息
|
||||
ss.result = {
|
||||
'ssid': ssid,
|
||||
'rssi': rssi,
|
||||
'auth': auth,
|
||||
'ch': ch,
|
||||
'bssid': bssid,
|
||||
};
|
||||
ss.over = true;
|
||||
return ss.result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 未找到状态或Wi-Fi信息时,返回 false
|
||||
return false;
|
||||
},
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user