import 'package:flutter/material.dart'; /// 状态卡片组件 class StatusCard extends StatelessWidget { final String title; final String value; final IconData icon; final Color? iconColor; final Color? backgroundColor; final String? subtitle; final VoidCallback? onTap; const StatusCard({ super.key, required this.title, required this.value, required this.icon, this.iconColor, this.backgroundColor, this.subtitle, this.onTap, }); @override Widget build(BuildContext context) { final theme = Theme.of(context); return Card( color: backgroundColor ?? theme.cardColor, elevation: 2, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(12), ), child: InkWell( onTap: onTap, borderRadius: BorderRadius.circular(12), child: Padding( padding: const EdgeInsets.all(16), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ Row( children: [ Icon( icon, color: iconColor ?? theme.colorScheme.primary, size: 24, ), const SizedBox(width: 8), Text( title, style: theme.textTheme.bodyMedium?.copyWith( color: theme.colorScheme.onSurfaceVariant, ), ), ], ), const SizedBox(height: 12), Text( value, style: theme.textTheme.headlineSmall?.copyWith( fontWeight: FontWeight.bold, ), ), if (subtitle != null) ...[ const SizedBox(height: 4), Text( subtitle!, style: theme.textTheme.bodySmall?.copyWith( color: theme.colorScheme.onSurfaceVariant, ), ), ], ], ), ), ), ); } } /// 网络状态指示器 class NetworkStatusIndicator extends StatelessWidget { final bool isConnected; final int latency; const NetworkStatusIndicator({ super.key, required this.isConnected, required this.latency, }); @override Widget build(BuildContext context) { final color = _getStatusColor(); final text = _getStatusText(); return Container( padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6), decoration: BoxDecoration( color: color.withValues(alpha: 0.1), borderRadius: BorderRadius.circular(20), border: Border.all(color: color.withValues(alpha: 0.3)), ), child: Row( mainAxisSize: MainAxisSize.min, children: [ Container( width: 8, height: 8, decoration: BoxDecoration( color: color, shape: BoxShape.circle, ), ), const SizedBox(width: 8), Text( text, style: TextStyle( color: color, fontWeight: FontWeight.w500, ), ), ], ), ); } Color _getStatusColor() { if (!isConnected) return Colors.red; if (latency < 0) return Colors.grey; if (latency > 200) return Colors.orange; if (latency > 100) return Colors.yellow.shade700; return Colors.green; } String _getStatusText() { if (!isConnected) return '离线'; if (latency < 0) return '检测中'; return '${latency}ms'; } }