更新样式

This commit is contained in:
wyf
2025-12-01 15:41:34 +08:00
parent 991bf97fd1
commit 1cc26aa46d
18 changed files with 502 additions and 677 deletions

View File

@@ -30,9 +30,11 @@ class _BodyDevicePageState extends State<BodyDeviceWidget> {
final BodyDeviceController bodyDeviceController = Get.find();
HomeController homeController = Get.find();
final GlobalKey addIconKey = GlobalKey();
final ScrollController _scrollController = ScrollController();
final ScrollController _myDeviceScrollController = ScrollController();
final ScrollController _cloudDeviceScrollController = ScrollController();
OverlayEntry? _popupEntry;
Timer? _timer;
late PageController _pageController;
void _showPopup() {
final renderBox =
@@ -42,20 +44,16 @@ class _BodyDevicePageState extends State<BodyDeviceWidget> {
final size = renderBox.size;
double popupWidth = 190.rpx;
// 移除之前的弹窗
_popupEntry?.remove();
// 创建新的OverlayEntry
_popupEntry = OverlayEntry(
builder: (context) => Stack(
children: [
// 半透明背景,点击后关闭弹窗
ModalBarrier(
dismissible: true,
color: Colors.transparent,
onDismiss: _hidePopup,
),
// 弹窗内容
Positioned(
top: position.dy + size.height + 26.rpx,
left: position.dx + size.width - popupWidth - 40.rpx,
@@ -81,36 +79,6 @@ class _BodyDevicePageState extends State<BodyDeviceWidget> {
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(height: 11.rpx),
// ClickableContainer(
// padding: EdgeInsets.symmetric(vertical: 10.rpx),
// backgroundColor: Colors.transparent,
// highlightColor:
// themeController.currentColor.sc16.withOpacity(0.1),
// borderRadius: 0.rpx,
// onTap: () {
// print('点击扫一扫');
// _hidePopup();
// TopSlideNotification.show(
// context,
// text: "待开发.提示".tr,
// textColor: themeController.currentColor.sc2,
// );
// },
// child: Container(
// width: double.infinity,
// child: Center(
// child: Text(
// '扫一扫.标题'.tr,
// style: TextStyle(
// fontSize: AppConstants().normal_text_fontSize,
// color: themeController.currentColor.sc3,
// ),
// ),
// ),
// ),
// ),
// SizedBox(height: 35.rpx),
ClickableContainer(
padding: EdgeInsets.symmetric(vertical: 10.rpx),
backgroundColor: Colors.transparent,
@@ -147,7 +115,6 @@ class _BodyDevicePageState extends State<BodyDeviceWidget> {
),
);
// 插入新的OverlayEntry
Overlay.of(context)!.insert(_popupEntry!);
}
@@ -161,6 +128,10 @@ class _BodyDevicePageState extends State<BodyDeviceWidget> {
bodyDeviceController.keyWord.value = "";
super.initState();
// 初始化PageController根据当前类型设置初始页面
_pageController = PageController(
initialPage: bodyDeviceController.model.type == 1 ? 0 : 1);
// 处理传入的type参数
if (widget.type != null && widget.type is Map) {
final bindType = widget.type['bind_type'];
@@ -169,23 +140,22 @@ class _BodyDevicePageState extends State<BodyDeviceWidget> {
if (bindType != null) {
bodyDeviceController.model.type = bindType;
homeController.model.type = bindType;
// 更新PageController到正确的位置
_pageController = PageController(
initialPage: bodyDeviceController.model.type == 1 ? 0 : 1);
}
// 初次请求设备列表
_fetchDeviceList().then((_) {
if (mac != null) {
// 延迟执行以确保列表已渲染
WidgetsBinding.instance.addPostFrameCallback((_) {
_scrollToDeviceWithMac(mac);
});
}
});
} else {
// 没有传入type时的默认逻辑
_fetchDeviceList();
}
// 每5秒定时请求一次
_timer = Timer.periodic(Duration(seconds: 5), (timer) {
_fetchDeviceList();
});
@@ -209,28 +179,54 @@ class _BodyDevicePageState extends State<BodyDeviceWidget> {
final deviceList = bodyDeviceController.deviceList.value;
final index = deviceList.indexWhere((device) => device['mac'] == mac);
if (index != -1 && _scrollController.hasClients) {
// 动态计算高度:最小为 501.rpx最大为 26.6% 屏幕高度
if (index != -1) {
final screenHeight = MediaQuery.of(Get.context!).size.height;
final dynamicItemHeight = (screenHeight * 0.266).rpx;
final itemHeight =
dynamicItemHeight < 501.rpx ? 501.rpx : dynamicItemHeight;
final spacing = 25.rpx;
final targetPosition = index * (itemHeight + spacing);
_scrollController.animateTo(
targetPosition,
duration: const Duration(milliseconds: 500),
curve: Curves.easeInOut,
);
// 根据当前类型选择对应的ScrollController
final currentScrollController =
bodyDeviceController.model.type == 1
? _myDeviceScrollController
: _cloudDeviceScrollController;
if (currentScrollController.hasClients) {
currentScrollController.animateTo(
targetPosition,
duration: const Duration(milliseconds: 500),
curve: Curves.easeInOut,
);
}
}
}
// 标签切换回调
void _onTabChanged(int index) {
_pageController.animateToPage(index,
duration: const Duration(milliseconds: 300), curve: Curves.easeInOut);
}
// 页面切换回调
void _onPageChanged(int index) {
int newType = index == 0 ? 1 : 2;
if (bodyDeviceController.model.type != newType) {
bodyDeviceController.model.type = newType;
homeController.model.type = newType;
bodyDeviceController.updateAll();
homeController.updateAll();
_fetchDeviceList();
}
}
@override
void dispose() {
_timer?.cancel(); // 页面销毁时取消定时器
_scrollController.dispose();
_timer?.cancel();
_myDeviceScrollController.dispose();
_cloudDeviceScrollController.dispose();
_pageController.dispose();
super.dispose();
}
@@ -238,7 +234,10 @@ class _BodyDevicePageState extends State<BodyDeviceWidget> {
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, bodysize) => GestureDetector(
// onTap: () => FocusScope.of(context).unfocus(),,
onTap: () {
_hidePopup();
FocusScope.of(context).unfocus();
},
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
@@ -262,7 +261,6 @@ class _BodyDevicePageState extends State<BodyDeviceWidget> {
child: Stack(
alignment: Alignment.center,
children: [
/// 居中标题
Text(
'体征检测设备.标题'.tr,
style: TextStyle(
@@ -288,7 +286,6 @@ class _BodyDevicePageState extends State<BodyDeviceWidget> {
highlightColor: themeController.currentColor.sc16,
padding: EdgeInsets.all(8.rpx),
onTap: () {
// 点击图标时,展示弹窗
if (_popupEntry == null) {
_showPopup();
} else {
@@ -310,7 +307,7 @@ class _BodyDevicePageState extends State<BodyDeviceWidget> {
centerTitle: false,
),
body: GestureDetector(
onTap: _hidePopup, // 点击空白处自动关闭弹窗
onTap: _hidePopup,
child: SafeArea(
top: true,
child: Padding(
@@ -335,6 +332,7 @@ class _BodyDevicePageState extends State<BodyDeviceWidget> {
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
// 标签切换部分 - 保持原有样式
Stack(
alignment: Alignment.bottomLeft,
children: [
@@ -348,19 +346,7 @@ class _BodyDevicePageState extends State<BodyDeviceWidget> {
.currentColor.sc3,
borderRadius: 8.rpx,
padding: EdgeInsets.all(0),
onTap: () async {
bodyDeviceController.model.type =
1;
homeController.model.type = 1;
await bodyDeviceController
.getDeviceList();
await bodyDeviceController
.getDeviceList();
await bodyDeviceController
.getSleepReport();
bodyDeviceController.updateAll();
homeController.updateAll();
},
onTap: () => _onTabChanged(0),
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
@@ -400,19 +386,7 @@ class _BodyDevicePageState extends State<BodyDeviceWidget> {
.currentColor.sc3,
borderRadius: 8.rpx,
padding: EdgeInsets.all(0),
onTap: () async {
homeController.model.type = 2;
bodyDeviceController.model.type =
2;
await bodyDeviceController
.getDeviceList();
await bodyDeviceController
.getDeviceList();
await bodyDeviceController
.getSleepReport();
bodyDeviceController.updateAll();
homeController.updateAll();
},
onTap: () => _onTabChanged(1),
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
@@ -451,7 +425,7 @@ class _BodyDevicePageState extends State<BodyDeviceWidget> {
],
),
Obx(() {
// 横线宽度固定为180.rpx
// 保持原有的横线宽度180.rpx
double lineWidth = 180.rpx;
return AnimatedPositioned(
duration: Duration(milliseconds: 300),
@@ -475,6 +449,7 @@ class _BodyDevicePageState extends State<BodyDeviceWidget> {
}),
],
),
// 搜索框部分保持不变
Container(
width:
MediaQuery.sizeOf(context).width * 0.38,
@@ -636,31 +611,63 @@ class _BodyDevicePageState extends State<BodyDeviceWidget> {
),
),
),
Obx(() {
final isEmpty =
bodyDeviceController.deviceList.value.isEmpty;
return Expanded(
child: isEmpty
? NullDataWidget()
: Padding(
padding: EdgeInsetsDirectional.fromSTEB(
30.rpx, 26.rpx, 30.rpx, 0),
child: SingleChildScrollView(
controller: _scrollController,
child: Column(
mainAxisSize: MainAxisSize.max,
children: bodyDeviceController
.deviceList.value
.map((device) =>
DeviceDataComponentWidget(
device: device))
.toList()
.divide(SizedBox(height: 25.rpx)),
),
),
),
);
}),
// 使用PageView替换原来的单一列表
Expanded(
child: PageView(
controller: _pageController,
onPageChanged: _onPageChanged,
children: [
// 我的e护页面
Obx(() {
final myDeviceList = bodyDeviceController.deviceList.value
.where((device) => device['type'] == 1 || device['bind_type'] == 1)
.toList();
return myDeviceList.isEmpty
? NullDataWidget()
: Padding(
padding: EdgeInsetsDirectional.fromSTEB(
30.rpx, 26.rpx, 30.rpx, 0),
child: SingleChildScrollView(
controller: _myDeviceScrollController,
child: Column(
mainAxisSize: MainAxisSize.max,
children: myDeviceList
.map((device) =>
DeviceDataComponentWidget(
device: device))
.toList()
.divide(SizedBox(height: 25.rpx)),
),
),
);
}),
// 云关爱页面
Obx(() {
final cloudDeviceList = bodyDeviceController.deviceList.value
.where((device) => device['type'] == 2 || device['bind_type'] == 2)
.toList();
return cloudDeviceList.isEmpty
? NullDataWidget()
: Padding(
padding: EdgeInsetsDirectional.fromSTEB(
30.rpx, 26.rpx, 30.rpx, 0),
child: SingleChildScrollView(
controller: _cloudDeviceScrollController,
child: Column(
mainAxisSize: MainAxisSize.max,
children: cloudDeviceList
.map((device) =>
DeviceDataComponentWidget(
device: device))
.toList()
.divide(SizedBox(height: 25.rpx)),
),
),
);
}),
],
),
),
],
),
),
@@ -717,4 +724,4 @@ class _BodyDevicePageState extends State<BodyDeviceWidget> {
),
);
}
}
}