对接远程遥控
This commit is contained in:
@@ -11,6 +11,7 @@ import 'package:maibu_satabot_v2/features/v2/home/presentation/widgets/work_orde
|
||||
import 'package:maibu_satabot_v2/features/v2/home/presentation/widgets/quick_entry_card.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/home/presentation/widgets/power_trend_chart.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/home/presentation/widgets/plant_overview_card.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/home/presentation/widgets/tcp_status_indicator.dart';
|
||||
|
||||
class HomeV2Page extends StatefulWidget {
|
||||
const HomeV2Page({super.key});
|
||||
@@ -100,10 +101,7 @@ class _HomeV2PageState extends State<HomeV2Page> {
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.qr_code_scanner, size: 24, color: Color(0xFF1D2129)),
|
||||
onPressed: () => print('点击扫码'),
|
||||
),
|
||||
const TcpStatusIndicator(),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -206,7 +204,12 @@ class _HomeV2PageState extends State<HomeV2Page> {
|
||||
super.didChangeDependencies();
|
||||
// 首次进入时自动加载数据,但不显示转圈
|
||||
if (_bloc.state is HomeV2Initial) {
|
||||
_bloc.add(const HomeV2LoadData());
|
||||
// 延迟 100ms,确保 AppUserCubit 状态已更新
|
||||
Future.delayed(const Duration(milliseconds: 100), () {
|
||||
if (mounted) {
|
||||
_bloc.add(const HomeV2LoadData());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:maibu_satabot_v2/core/network/tcp/tcp_status_cubit.dart';
|
||||
|
||||
/// TCP 连接状态指示灯组件
|
||||
class TcpStatusIndicator extends StatefulWidget {
|
||||
const TcpStatusIndicator({super.key});
|
||||
|
||||
@override
|
||||
State<TcpStatusIndicator> createState() => _TcpStatusIndicatorState();
|
||||
}
|
||||
|
||||
class _TcpStatusIndicatorState extends State<TcpStatusIndicator>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late TcpStatusCubit _tcpStatusCubit;
|
||||
bool _hasActivity = false;
|
||||
late AnimationController _controller;
|
||||
late Animation<double> _animation;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tcpStatusCubit = GetIt.I<TcpStatusCubit>();
|
||||
|
||||
_controller = AnimationController(
|
||||
duration: const Duration(milliseconds: 1500),
|
||||
vsync: this,
|
||||
)..repeat(reverse: true);
|
||||
|
||||
_animation = Tween<double>(begin: 0.6, end: 1.0).animate(
|
||||
CurvedAnimation(parent: _controller, curve: Curves.easeInOut),
|
||||
);
|
||||
|
||||
_tcpStatusCubit.stream.listen((state) {
|
||||
if (state.status != TcpConnectionStatus.disconnected) {
|
||||
_hasActivity = true;
|
||||
}
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final state = _tcpStatusCubit.state;
|
||||
|
||||
Color color;
|
||||
String tooltip;
|
||||
bool shouldAnimate;
|
||||
|
||||
switch (state.status) {
|
||||
case TcpConnectionStatus.connected:
|
||||
color = Colors.green;
|
||||
tooltip = 'TCP已连接';
|
||||
shouldAnimate = false;
|
||||
break;
|
||||
case TcpConnectionStatus.connecting:
|
||||
color = Colors.yellow;
|
||||
tooltip = 'TCP连接中...';
|
||||
shouldAnimate = true;
|
||||
break;
|
||||
case TcpConnectionStatus.error:
|
||||
color = Colors.red;
|
||||
tooltip = state.errorMessage ?? 'TCP连接错误';
|
||||
shouldAnimate = false;
|
||||
break;
|
||||
case TcpConnectionStatus.disconnected:
|
||||
default:
|
||||
color = Colors.grey;
|
||||
tooltip = 'TCP未连接';
|
||||
shouldAnimate = false;
|
||||
break;
|
||||
}
|
||||
|
||||
return Tooltip(
|
||||
message: tooltip,
|
||||
child: AnimatedBuilder(
|
||||
animation: _animation,
|
||||
builder: (context, child) {
|
||||
final opacity = shouldAnimate ? _animation.value : 1.0;
|
||||
return Container(
|
||||
width: 12,
|
||||
height: 12,
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(opacity),
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: state.status == TcpConnectionStatus.connected
|
||||
? [
|
||||
BoxShadow(
|
||||
color: Colors.green.withOpacity(0.5 * opacity),
|
||||
blurRadius: 6 * opacity,
|
||||
spreadRadius: 2 * opacity,
|
||||
),
|
||||
]
|
||||
: [],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user