M1.1 收尾: - 24项 P0/P1/P2 bug 修复 (Rust 107 tests + Flutter 15 tests) - Flutter App v0.3: cupertino_icons 修复, 单元测试, 调试面板, APK 52.6MB - 示例插件完善: manifest.json + 请求/响应示范 + 7个测试 - API 文档重写 (以 routes.rs 为唯一权威) - MILESTONES.md 更新至 100% M1.2 启动: - P0: 插件管理 API 闭环 (handle_manager_message Custom 分支 + broadcast_plugin_states) - ServiceManager 集成测试 8/8 (tests/m1_2_service_manager.rs) - M1.2 测试计划 (docs/M1.2_TEST_PLAN.md, 18个E2E场景) - 动态插件系统: auto_rollback + version_manager GC + 路径穿越防护 总计: Rust 115/115 测试, Flutter 15/15 测试, 零 warning Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
78 lines
2.9 KiB
Dart
78 lines
2.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../services/web_socket_service.dart';
|
|
|
|
class ConnectionStatusBanner extends StatelessWidget {
|
|
const ConnectionStatusBanner({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final webSocketService = context.read<WebSocketService>();
|
|
|
|
return StreamBuilder<SocketConnectionStatus>(
|
|
stream: webSocketService.connectionState,
|
|
initialData: webSocketService.connectionStatus,
|
|
builder: (context, snapshot) {
|
|
final connectionStatus =
|
|
snapshot.data ?? SocketConnectionStatus.disconnected;
|
|
final isVisible = connectionStatus != SocketConnectionStatus.connected;
|
|
final isConnecting =
|
|
connectionStatus == SocketConnectionStatus.connecting;
|
|
|
|
return AnimatedContainer(
|
|
duration: const Duration(milliseconds: 250),
|
|
curve: Curves.easeInOut,
|
|
height: isVisible ? 52 : 0,
|
|
color:
|
|
isConnecting ? Colors.amber.shade700 : Colors.redAccent.shade700,
|
|
child: isVisible
|
|
? SafeArea(
|
|
bottom: false,
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 16,
|
|
vertical: 10,
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
isConnecting
|
|
? '正在重连...(第${webSocketService.retryCount.clamp(1, 999)}次)'
|
|
: '连接断开',
|
|
style: Theme.of(context)
|
|
.textTheme
|
|
.bodyMedium
|
|
?.copyWith(
|
|
color: Colors.black,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
),
|
|
if (!isConnecting)
|
|
TextButton(
|
|
onPressed: () {
|
|
webSocketService.manualReconnect();
|
|
},
|
|
style: TextButton.styleFrom(
|
|
foregroundColor: Colors.white,
|
|
backgroundColor: Colors.black26,
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 12,
|
|
vertical: 8,
|
|
),
|
|
),
|
|
child: const Text('重试'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
)
|
|
: null,
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|