simple_log_card.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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 StatefulWidget {
  7. final ConsoleLogEntry log;
  8. const SimpleLogCard({super.key, required this.log});
  9. @override
  10. State<SimpleLogCard> createState() => _SimpleLogCardState();
  11. }
  12. class _SimpleLogCardState extends State<SimpleLogCard>
  13. with SingleTickerProviderStateMixin {
  14. bool _isExpanded = false;
  15. late AnimationController _animationController;
  16. late Animation<double> _expandAnimation;
  17. late Animation<double> _iconRotation;
  18. @override
  19. void initState() {
  20. super.initState();
  21. _animationController = AnimationController(
  22. duration: const Duration(milliseconds: 250),
  23. vsync: this,
  24. );
  25. _expandAnimation = CurvedAnimation(
  26. parent: _animationController,
  27. curve: Curves.easeInOut,
  28. );
  29. _iconRotation =
  30. Tween<double>(begin: 0.0, end: 0.5).animate(_expandAnimation);
  31. }
  32. @override
  33. void dispose() {
  34. _animationController.dispose();
  35. super.dispose();
  36. }
  37. @override
  38. Widget build(BuildContext context) {
  39. final fullMessage = '${widget.log.tag}: ${widget.log.message}';
  40. return Container(
  41. margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 3),
  42. decoration: BoxDecoration(
  43. borderRadius: BorderRadius.circular(12),
  44. gradient: const LinearGradient(
  45. begin: Alignment.topLeft,
  46. end: Alignment.bottomRight,
  47. colors: [
  48. Colors.white,
  49. Colors.blue,
  50. ],
  51. ),
  52. border: Border.all(color: Colors.blue[200]!, width: 1),
  53. boxShadow: [
  54. BoxShadow(
  55. color: Colors.blue[100]!.withValues(alpha: 0.3),
  56. blurRadius: 6,
  57. offset: const Offset(0, 2),
  58. ),
  59. ],
  60. ),
  61. child: Column(
  62. children: [
  63. // 主要内容区域
  64. InkWell(
  65. onTap: _toggleExpansion,
  66. borderRadius: const BorderRadius.vertical(top: Radius.circular(12)),
  67. child: Padding(
  68. padding: const EdgeInsets.all(16),
  69. child: Row(
  70. children: [
  71. // 状态指示器
  72. Container(
  73. width: 10,
  74. height: 10,
  75. decoration: BoxDecoration(
  76. gradient: LinearGradient(
  77. colors: [Colors.cyan[400]!, Colors.teal[500]!],
  78. ),
  79. shape: BoxShape.circle,
  80. boxShadow: [
  81. BoxShadow(
  82. color: Colors.cyan[300]!.withValues(alpha: 0.5),
  83. blurRadius: 4,
  84. offset: const Offset(0, 1),
  85. ),
  86. ],
  87. ),
  88. ),
  89. const SizedBox(width: 12),
  90. // 时间标签
  91. Container(
  92. padding:
  93. const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
  94. decoration: BoxDecoration(
  95. gradient: LinearGradient(
  96. colors: [Colors.purple[500]!, Colors.pink[500]!],
  97. ),
  98. borderRadius: BorderRadius.circular(10),
  99. boxShadow: [
  100. BoxShadow(
  101. color: Colors.purple[200]!.withValues(alpha: 0.5),
  102. blurRadius: 3,
  103. offset: const Offset(0, 1),
  104. ),
  105. ],
  106. ),
  107. child: Text(
  108. widget.log.formattedTime,
  109. style: const TextStyle(
  110. fontFamily: 'monospace',
  111. fontSize: 10,
  112. color: Colors.white,
  113. fontWeight: FontWeight.bold,
  114. ),
  115. ),
  116. ),
  117. const SizedBox(width: 12),
  118. // 日志内容
  119. Expanded(
  120. child: Text(
  121. fullMessage,
  122. style: const TextStyle(
  123. fontFamily: 'monospace',
  124. fontSize: 13,
  125. color: Colors.black87,
  126. fontWeight: FontWeight.w500,
  127. ),
  128. maxLines: 2,
  129. overflow: TextOverflow.ellipsis,
  130. ),
  131. ),
  132. // 展开/收起图标
  133. AnimatedBuilder(
  134. animation: _iconRotation,
  135. builder: (context, child) {
  136. return Transform.rotate(
  137. angle: _iconRotation.value * 3.14159,
  138. child: Container(
  139. padding: const EdgeInsets.all(4),
  140. decoration: BoxDecoration(
  141. color: Colors.blue[100],
  142. shape: BoxShape.circle,
  143. ),
  144. child: Icon(
  145. Icons.keyboard_arrow_down,
  146. color: Colors.blue[700],
  147. size: 16,
  148. ),
  149. ),
  150. );
  151. },
  152. ),
  153. ],
  154. ),
  155. ),
  156. ),
  157. // 展开的详细内容
  158. SizeTransition(
  159. sizeFactor: _expandAnimation,
  160. child: Container(
  161. width: double.infinity,
  162. decoration: BoxDecoration(
  163. gradient: LinearGradient(
  164. begin: Alignment.topCenter,
  165. end: Alignment.bottomCenter,
  166. colors: [Colors.blue[50]!, Colors.indigo[50]!],
  167. ),
  168. borderRadius: const BorderRadius.only(
  169. bottomLeft: Radius.circular(12),
  170. bottomRight: Radius.circular(12),
  171. ),
  172. ),
  173. child: Column(
  174. children: [
  175. // 分割线
  176. Container(
  177. height: 2,
  178. margin: const EdgeInsets.symmetric(horizontal: 16),
  179. decoration: BoxDecoration(
  180. gradient: LinearGradient(
  181. colors: [Colors.blue[300]!, Colors.purple[300]!],
  182. ),
  183. borderRadius: BorderRadius.circular(1),
  184. ),
  185. ),
  186. // 详细内容
  187. Padding(
  188. padding: const EdgeInsets.all(16),
  189. child: Column(
  190. crossAxisAlignment: CrossAxisAlignment.start,
  191. children: [
  192. Row(
  193. children: [
  194. Container(
  195. padding: const EdgeInsets.symmetric(
  196. horizontal: 10, vertical: 4),
  197. decoration: BoxDecoration(
  198. gradient: LinearGradient(
  199. colors: [
  200. Colors.orange[500]!,
  201. Colors.deepOrange[600]!
  202. ],
  203. ),
  204. borderRadius: BorderRadius.circular(8),
  205. boxShadow: [
  206. BoxShadow(
  207. color: Colors.orange[200]!.withValues(alpha: 0.5),
  208. blurRadius: 3,
  209. offset: const Offset(0, 1),
  210. ),
  211. ],
  212. ),
  213. child: const Text(
  214. '完整内容',
  215. style: TextStyle(
  216. fontWeight: FontWeight.bold,
  217. color: Colors.white,
  218. fontSize: 11,
  219. ),
  220. ),
  221. ),
  222. const Spacer(),
  223. ElevatedButton.icon(
  224. icon: const Icon(Icons.copy, size: 14),
  225. label: const Text('复制'),
  226. style: ElevatedButton.styleFrom(
  227. backgroundColor: Colors.teal[600],
  228. foregroundColor: Colors.white,
  229. elevation: 3,
  230. padding: const EdgeInsets.symmetric(
  231. horizontal: 12, vertical: 6),
  232. shape: RoundedRectangleBorder(
  233. borderRadius: BorderRadius.circular(10),
  234. ),
  235. ),
  236. onPressed: () => _copyToClipboard(fullMessage),
  237. ),
  238. ],
  239. ),
  240. const SizedBox(height: 12),
  241. Container(
  242. width: double.infinity,
  243. padding: const EdgeInsets.all(16),
  244. decoration: BoxDecoration(
  245. color: Colors.grey[50],
  246. borderRadius: BorderRadius.circular(8),
  247. border:
  248. Border.all(color: Colors.blue[200]!, width: 1),
  249. ),
  250. child: SelectableText(
  251. fullMessage,
  252. style: const TextStyle(
  253. fontFamily: 'monospace',
  254. fontSize: 13,
  255. color: Colors.black87,
  256. height: 1.4,
  257. ),
  258. ),
  259. ),
  260. ],
  261. ),
  262. ),
  263. ],
  264. ),
  265. ),
  266. ),
  267. ],
  268. ),
  269. );
  270. }
  271. void _toggleExpansion() {
  272. setState(() {
  273. _isExpanded = !_isExpanded;
  274. if (_isExpanded) {
  275. _animationController.forward();
  276. } else {
  277. _animationController.reverse();
  278. }
  279. });
  280. }
  281. void _copyToClipboard(String text) {
  282. Clipboard.setData(ClipboardData(text: text));
  283. Get.snackbar(
  284. '🎉 复制成功',
  285. '日志内容已复制到剪贴板',
  286. duration: const Duration(seconds: 1),
  287. snackPosition: SnackPosition.bottom,
  288. backgroundColor: Colors.green[500],
  289. colorText: Colors.white,
  290. borderRadius: 10,
  291. margin: const EdgeInsets.all(16),
  292. boxShadows: [
  293. BoxShadow(
  294. color: Colors.green[200]!.withValues(alpha: 0.5),
  295. blurRadius: 6,
  296. offset: const Offset(0, 3),
  297. ),
  298. ],
  299. );
  300. }
  301. }