更新睡眠报告
This commit is contained in:
90
lib/component/base/GradientSwitch.dart
Normal file
90
lib/component/base/GradientSwitch.dart
Normal file
@@ -0,0 +1,90 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class GradientSwitch extends StatefulWidget {
|
||||
final bool value;
|
||||
final ValueChanged<bool> onChanged;
|
||||
final Gradient activeGradient;
|
||||
final Color inactiveColor;
|
||||
final Color activeThumbColor;
|
||||
final Color inactiveThumbColor;
|
||||
|
||||
const GradientSwitch({
|
||||
super.key,
|
||||
required this.value,
|
||||
required this.onChanged,
|
||||
required this.activeGradient,
|
||||
this.inactiveColor = Colors.grey,
|
||||
this.activeThumbColor = Colors.white,
|
||||
this.inactiveThumbColor = Colors.white,
|
||||
});
|
||||
|
||||
@override
|
||||
State<GradientSwitch> createState() => _GradientSwitchState();
|
||||
}
|
||||
|
||||
class _GradientSwitchState extends State<GradientSwitch>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late AnimationController _controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = AnimationController(
|
||||
vsync: this, duration: const Duration(milliseconds: 200));
|
||||
_controller.value = widget.value ? 1.0 : 0.0;
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant GradientSwitch oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.value != oldWidget.value) {
|
||||
widget.value ? _controller.forward() : _controller.reverse();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: () => widget.onChanged(!widget.value),
|
||||
child: AnimatedBuilder(
|
||||
animation: _controller,
|
||||
builder: (context, child) {
|
||||
final align = Alignment.lerp(
|
||||
Alignment.centerLeft, Alignment.centerRight, _controller.value)!;
|
||||
|
||||
// 动态计算小球颜色(线性过渡)
|
||||
final thumbColor = Color.lerp(widget.inactiveThumbColor,
|
||||
widget.activeThumbColor, _controller.value)!;
|
||||
|
||||
return Container(
|
||||
width: 60,
|
||||
height: 30,
|
||||
padding: const EdgeInsets.all(3),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(30),
|
||||
gradient: widget.value ? widget.activeGradient : null,
|
||||
color: widget.value ? null : widget.inactiveColor,
|
||||
),
|
||||
child: Align(
|
||||
alignment: align,
|
||||
child: Container(
|
||||
width: 24,
|
||||
height: 24,
|
||||
decoration: BoxDecoration(
|
||||
color: thumbColor,
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: const [
|
||||
BoxShadow(
|
||||
color: Colors.black26,
|
||||
blurRadius: 2,
|
||||
offset: Offset(0, 1)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ class DynamicReportDetailWidget extends StatelessWidget {
|
||||
final List<SleepDataModuleWidget> sleepDataModuleWidgets;
|
||||
final ThemeController themeController = Get.find();
|
||||
final Map targetDevice;
|
||||
late ScrollController _scrollController;
|
||||
|
||||
DynamicReportDetailWidget({
|
||||
required this.sleepDateWidgets,
|
||||
@@ -25,6 +26,18 @@ class DynamicReportDetailWidget extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
_scrollController = ScrollController();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (_scrollController.hasClients) {
|
||||
// _scrollController.jumpTo(_scrollController.position.maxScrollExtent);
|
||||
// 如果你希望有动画,用下面这句替代 jumpTo:
|
||||
_scrollController.animateTo(
|
||||
_scrollController.position.maxScrollExtent,
|
||||
duration: Duration(milliseconds: 300),
|
||||
curve: Curves.easeOut,
|
||||
);
|
||||
}
|
||||
});
|
||||
return Padding(
|
||||
padding: EdgeInsetsDirectional.fromSTEB(0, 25.rpx, 0, 25.rpx),
|
||||
child: Container(
|
||||
@@ -40,7 +53,7 @@ class DynamicReportDetailWidget extends StatelessWidget {
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
_buildHeader(context,targetDevice),
|
||||
_buildHeader(context, targetDevice),
|
||||
SizedBox(
|
||||
height: 33.rpx,
|
||||
),
|
||||
@@ -67,7 +80,7 @@ class DynamicReportDetailWidget extends StatelessWidget {
|
||||
borderRadius: 0,
|
||||
padding: EdgeInsets.zero,
|
||||
onTap: () async {
|
||||
await Get.toNamed("/bodyDevice",arguments: targetDevice);
|
||||
await Get.toNamed("/bodyDevice", arguments: targetDevice);
|
||||
},
|
||||
child: Text(
|
||||
'${targetDevice['person']?['name'] == null ? '未命名'.tr : targetDevice['person']['name']}',
|
||||
@@ -132,6 +145,7 @@ class DynamicReportDetailWidget extends StatelessWidget {
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(),
|
||||
child: SingleChildScrollView(
|
||||
controller: _scrollController, // ⭐️ 关键点
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
|
||||
@@ -101,76 +101,51 @@ class _SleepDataModuleWidgetState extends State<SleepDataModuleWidget> {
|
||||
),
|
||||
],
|
||||
),
|
||||
// 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,
|
||||
),
|
||||
borderRadius: 8.rpx,
|
||||
onTap: () {
|
||||
print('Button pressed ...');
|
||||
},
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
constraints: BoxConstraints(
|
||||
minWidth: 43.rpx,
|
||||
minHeight: 36.rpx,
|
||||
if (widget.data['level'] != null)
|
||||
ClickableContainer(
|
||||
backgroundColor: (widget.data['color'] == null ||
|
||||
widget.data['color'].toString().isEmpty)
|
||||
? Colors.transparent
|
||||
: stringToColor(widget.data['color']),
|
||||
highlightColor: themeController.currentColor.sc3,
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 0.rpx,
|
||||
vertical: 0.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,
|
||||
),
|
||||
borderRadius: 8.rpx,
|
||||
onTap: () {
|
||||
print('Button pressed ...');
|
||||
},
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
constraints: BoxConstraints(
|
||||
minWidth: 43.rpx,
|
||||
minHeight: 36.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,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
].divide(SizedBox(width: 0.rpx)),
|
||||
),
|
||||
Text(
|
||||
'${widget.data['range']}',
|
||||
"正常值".tr +
|
||||
'${(widget.data['range'] ?? '').toString().isEmpty ? '未知数据'.tr : widget.data['range']}',
|
||||
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: AppConstants().small_text_fontSize,
|
||||
letterSpacing: 0.0,
|
||||
color: themeController.currentColor.sc4,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user