simple_log_card.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/services.dart';
  3. import 'package:get/get.dart';
  4. import 'ix_developer_tools.dart';
  5. /// 轻量级日志条目组件 - 纵向排列,点击弹窗显示完整内容
  6. class SimpleLogCard extends StatelessWidget {
  7. final ConsoleLogEntry log;
  8. const SimpleLogCard({super.key, required this.log});
  9. @override
  10. Widget build(BuildContext context) {
  11. return InkWell(
  12. onTap: () => _showDetailDialog(context),
  13. borderRadius: BorderRadius.circular(10),
  14. child: Container(
  15. margin: const EdgeInsets.symmetric(horizontal: 4, vertical: 4),
  16. padding: const EdgeInsets.all(12),
  17. decoration: BoxDecoration(
  18. color: Colors.white,
  19. borderRadius: BorderRadius.circular(10),
  20. border: Border.all(color: Colors.grey[200]!, width: 1),
  21. boxShadow: [
  22. BoxShadow(
  23. color: Colors.black.withValues(alpha: 0.03),
  24. blurRadius: 4,
  25. offset: const Offset(0, 1),
  26. ),
  27. ],
  28. ),
  29. child: Column(
  30. crossAxisAlignment: CrossAxisAlignment.start,
  31. children: [
  32. // 第一行:时间、Tag
  33. Row(
  34. children: [
  35. // 状态指示点
  36. Container(
  37. width: 8,
  38. height: 8,
  39. decoration: BoxDecoration(
  40. color: _getTagColor(),
  41. shape: BoxShape.circle,
  42. ),
  43. ),
  44. const SizedBox(width: 8),
  45. // Tag标签
  46. Container(
  47. padding: const EdgeInsets.symmetric(
  48. horizontal: 8,
  49. vertical: 3,
  50. ),
  51. decoration: BoxDecoration(
  52. color: _getTagColor().withValues(alpha: 0.1),
  53. borderRadius: BorderRadius.circular(4),
  54. ),
  55. child: Text(
  56. log.tag,
  57. style: TextStyle(
  58. fontSize: 11,
  59. color: _getTagColor(),
  60. fontWeight: FontWeight.w600,
  61. ),
  62. ),
  63. ),
  64. const Spacer(),
  65. // 时间
  66. Text(
  67. log.formattedTime,
  68. style: TextStyle(
  69. fontFamily: 'monospace',
  70. fontSize: 10,
  71. color: Colors.grey[400],
  72. ),
  73. ),
  74. ],
  75. ),
  76. const SizedBox(height: 8),
  77. // 第二行:日志内容(完整显示,最多3行)
  78. Text(
  79. log.message,
  80. style: const TextStyle(
  81. fontSize: 12,
  82. color: Colors.black87,
  83. height: 1.4,
  84. ),
  85. maxLines: 3,
  86. overflow: TextOverflow.ellipsis,
  87. ),
  88. ],
  89. ),
  90. ),
  91. );
  92. }
  93. Color _getTagColor() {
  94. final tag = log.tag.toLowerCase();
  95. if (tag.contains('error') || tag.contains('err')) return Colors.red;
  96. if (tag.contains('warn')) return Colors.orange;
  97. if (tag.contains('info')) return Colors.blue;
  98. if (tag.contains('debug')) return Colors.purple;
  99. if (tag.contains('api') || tag.contains('http')) return Colors.teal;
  100. if (tag.contains('vpn') || tag.contains('xray')) return Colors.indigo;
  101. return Colors.blueGrey;
  102. }
  103. void _showDetailDialog(BuildContext context) {
  104. showDialog(
  105. context: context,
  106. builder: (context) => _LogDetailDialog(log: log),
  107. );
  108. }
  109. }
  110. /// 日志详情弹窗 - 纵向排列
  111. class _LogDetailDialog extends StatelessWidget {
  112. final ConsoleLogEntry log;
  113. const _LogDetailDialog({required this.log});
  114. @override
  115. Widget build(BuildContext context) {
  116. return Dialog(
  117. backgroundColor: Colors.grey[50],
  118. shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
  119. insetPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
  120. child: Container(
  121. width: Get.width * 0.92,
  122. constraints: BoxConstraints(maxHeight: Get.height * 0.75),
  123. child: Column(
  124. mainAxisSize: MainAxisSize.min,
  125. crossAxisAlignment: CrossAxisAlignment.start,
  126. children: [
  127. // 头部
  128. Container(
  129. padding: const EdgeInsets.all(16),
  130. decoration: BoxDecoration(
  131. color: Colors.white,
  132. borderRadius: const BorderRadius.vertical(
  133. top: Radius.circular(16),
  134. ),
  135. boxShadow: [
  136. BoxShadow(
  137. color: Colors.black.withValues(alpha: 0.05),
  138. blurRadius: 4,
  139. offset: const Offset(0, 2),
  140. ),
  141. ],
  142. ),
  143. child: Column(
  144. crossAxisAlignment: CrossAxisAlignment.start,
  145. children: [
  146. // 第一行:Tag、时间、操作按钮
  147. Row(
  148. children: [
  149. // Tag
  150. Container(
  151. padding: const EdgeInsets.symmetric(
  152. horizontal: 10,
  153. vertical: 5,
  154. ),
  155. decoration: BoxDecoration(
  156. color: _getTagColor().withValues(alpha: 0.1),
  157. borderRadius: BorderRadius.circular(6),
  158. border: Border.all(
  159. color: _getTagColor().withValues(alpha: 0.3),
  160. ),
  161. ),
  162. child: Text(
  163. log.tag,
  164. style: TextStyle(
  165. fontSize: 13,
  166. fontWeight: FontWeight.w600,
  167. color: _getTagColor(),
  168. ),
  169. ),
  170. ),
  171. const SizedBox(width: 10),
  172. // 时间
  173. Container(
  174. padding: const EdgeInsets.symmetric(
  175. horizontal: 8,
  176. vertical: 4,
  177. ),
  178. decoration: BoxDecoration(
  179. color: Colors.grey[100],
  180. borderRadius: BorderRadius.circular(6),
  181. ),
  182. child: Text(
  183. log.formattedTime,
  184. style: TextStyle(
  185. fontSize: 12,
  186. color: Colors.grey[700],
  187. fontFamily: 'monospace',
  188. fontWeight: FontWeight.w500,
  189. ),
  190. ),
  191. ),
  192. const Spacer(),
  193. // 复制按钮
  194. InkWell(
  195. onTap: () =>
  196. _copyToClipboard('${log.tag}: ${log.message}'),
  197. borderRadius: BorderRadius.circular(8),
  198. child: Container(
  199. padding: const EdgeInsets.symmetric(
  200. horizontal: 10,
  201. vertical: 6,
  202. ),
  203. decoration: BoxDecoration(
  204. color: Colors.grey[100],
  205. borderRadius: BorderRadius.circular(8),
  206. ),
  207. child: Row(
  208. mainAxisSize: MainAxisSize.min,
  209. children: [
  210. Icon(
  211. Icons.copy,
  212. size: 14,
  213. color: Colors.grey[600],
  214. ),
  215. const SizedBox(width: 4),
  216. Text(
  217. '复制',
  218. style: TextStyle(
  219. fontSize: 12,
  220. fontWeight: FontWeight.w500,
  221. color: Colors.grey[600],
  222. ),
  223. ),
  224. ],
  225. ),
  226. ),
  227. ),
  228. const SizedBox(width: 8),
  229. // 关闭按钮
  230. InkWell(
  231. onTap: () => Navigator.pop(context),
  232. borderRadius: BorderRadius.circular(8),
  233. child: Container(
  234. padding: const EdgeInsets.all(6),
  235. decoration: BoxDecoration(
  236. color: Colors.grey[100],
  237. borderRadius: BorderRadius.circular(8),
  238. ),
  239. child: Icon(
  240. Icons.close,
  241. size: 18,
  242. color: Colors.grey[600],
  243. ),
  244. ),
  245. ),
  246. ],
  247. ),
  248. ],
  249. ),
  250. ),
  251. // 内容标题
  252. Padding(
  253. padding: const EdgeInsets.fromLTRB(16, 16, 16, 8),
  254. child: Row(
  255. children: [
  256. Icon(
  257. Icons.article_outlined,
  258. size: 16,
  259. color: Colors.grey[600],
  260. ),
  261. const SizedBox(width: 6),
  262. Text(
  263. '日志内容',
  264. style: TextStyle(
  265. fontSize: 13,
  266. fontWeight: FontWeight.w600,
  267. color: Colors.grey[700],
  268. ),
  269. ),
  270. ],
  271. ),
  272. ),
  273. // 内容
  274. Flexible(
  275. child: Container(
  276. margin: const EdgeInsets.fromLTRB(16, 0, 16, 16),
  277. decoration: BoxDecoration(
  278. color: Colors.white,
  279. borderRadius: BorderRadius.circular(12),
  280. border: Border.all(color: Colors.grey[200]!),
  281. ),
  282. child: SingleChildScrollView(
  283. padding: const EdgeInsets.all(16),
  284. child: SelectableText(
  285. log.message,
  286. style: const TextStyle(
  287. fontFamily: 'monospace',
  288. fontSize: 13,
  289. color: Colors.black87,
  290. height: 1.6,
  291. ),
  292. ),
  293. ),
  294. ),
  295. ),
  296. ],
  297. ),
  298. ),
  299. );
  300. }
  301. Color _getTagColor() {
  302. final tag = log.tag.toLowerCase();
  303. if (tag.contains('error') || tag.contains('err')) return Colors.red;
  304. if (tag.contains('warn')) return Colors.orange;
  305. if (tag.contains('info')) return Colors.blue;
  306. if (tag.contains('debug')) return Colors.purple;
  307. if (tag.contains('api') || tag.contains('http')) return Colors.teal;
  308. if (tag.contains('vpn') || tag.contains('xray')) return Colors.indigo;
  309. return Colors.blueGrey;
  310. }
  311. void _copyToClipboard(String text) {
  312. Clipboard.setData(ClipboardData(text: text));
  313. Get.snackbar(
  314. '已复制',
  315. '日志内容已复制到剪贴板',
  316. duration: const Duration(seconds: 1),
  317. snackPosition: SnackPosition.bottom,
  318. backgroundColor: Colors.grey[800],
  319. colorText: Colors.white,
  320. borderRadius: 10,
  321. margin: const EdgeInsets.all(16),
  322. icon: const Padding(
  323. padding: EdgeInsets.only(left: 12),
  324. child: Icon(Icons.check_circle, color: Colors.white, size: 20),
  325. ),
  326. );
  327. }
  328. }