app_skeletons.dart 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. import 'package:flutter/material.dart';
  2. import 'package:skeletonizer/skeletonizer.dart';
  3. import '../../core/theme/app_colors_extension.dart';
  4. /// 骨架占位卡片容器(列表加载态)
  5. class SkeletonLoadingList extends StatelessWidget {
  6. final int cardCount;
  7. final Widget Function() cardBuilder;
  8. final EdgeInsetsGeometry padding;
  9. const SkeletonLoadingList({
  10. super.key,
  11. this.cardCount = 5,
  12. this.cardBuilder = _defaultBuilder,
  13. this.padding = const EdgeInsets.fromLTRB(16, 16, 16, 24),
  14. });
  15. static Widget _defaultBuilder() => const SkeletonListCard();
  16. @override
  17. Widget build(BuildContext context) {
  18. return SingleChildScrollView(
  19. padding: padding,
  20. child: Skeletonizer(
  21. enabled: true,
  22. child: Column(
  23. children: List.generate(
  24. cardCount,
  25. (_) => Padding(
  26. padding: const EdgeInsets.only(bottom: 16),
  27. child: cardBuilder(),
  28. ),
  29. ),
  30. ),
  31. ),
  32. );
  33. }
  34. }
  35. /// 匹配 ListCard 的骨架占位
  36. class SkeletonListCard extends StatelessWidget {
  37. const SkeletonListCard({super.key});
  38. @override
  39. Widget build(BuildContext context) {
  40. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  41. return Skeletonizer(
  42. enabled: true,
  43. child: Container(
  44. padding: const EdgeInsets.all(12),
  45. decoration: BoxDecoration(
  46. color: colors.bgCard,
  47. borderRadius: BorderRadius.circular(8),
  48. ),
  49. child: Column(
  50. crossAxisAlignment: CrossAxisAlignment.start,
  51. children: [
  52. Row(
  53. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  54. children: [
  55. Bone.text(width: 120),
  56. Bone.text(width: 80),
  57. ],
  58. ),
  59. SizedBox(height: 6),
  60. Bone.text(width: 140),
  61. SizedBox(height: 6),
  62. Bone.text(),
  63. SizedBox(height: 8),
  64. Row(
  65. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  66. children: [
  67. Bone.text(width: 100),
  68. Bone(width: 48, height: 20, borderRadius: BorderRadius.circular(4)),
  69. ],
  70. ),
  71. ],
  72. ),
  73. ),
  74. );
  75. }
  76. }
  77. /// 匹配车辆列表卡片的骨架占位
  78. class SkeletonVehicleCard extends StatelessWidget {
  79. const SkeletonVehicleCard({super.key});
  80. @override
  81. Widget build(BuildContext context) {
  82. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  83. return Skeletonizer(
  84. enabled: true,
  85. child: Container(
  86. padding: const EdgeInsets.all(12),
  87. decoration: BoxDecoration(
  88. color: colors.bgCard,
  89. borderRadius: BorderRadius.circular(8),
  90. ),
  91. child: Column(
  92. crossAxisAlignment: CrossAxisAlignment.start,
  93. children: [
  94. Row(
  95. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  96. children: [
  97. Bone.text(width: 100),
  98. Bone(width: 48, height: 20, borderRadius: BorderRadius.circular(4)),
  99. ],
  100. ),
  101. SizedBox(height: 6),
  102. Row(
  103. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  104. children: [
  105. Bone.text(width: 140),
  106. Bone(width: 40, height: 16, borderRadius: BorderRadius.circular(4)),
  107. ],
  108. ),
  109. SizedBox(height: 6),
  110. Row(
  111. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  112. children: [
  113. Expanded(child: Bone.text()),
  114. const SizedBox(width: 8),
  115. Bone.text(width: 120),
  116. ],
  117. ),
  118. ],
  119. ),
  120. ),
  121. );
  122. }
  123. }
  124. /// 匹配外勤日志卡片的骨架占位
  125. class SkeletonOutingLogCard extends StatelessWidget {
  126. const SkeletonOutingLogCard({super.key});
  127. @override
  128. Widget build(BuildContext context) {
  129. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  130. return Skeletonizer(
  131. enabled: true,
  132. child: Container(
  133. padding: const EdgeInsets.all(12),
  134. decoration: BoxDecoration(
  135. color: colors.bgCard,
  136. borderRadius: BorderRadius.circular(8),
  137. ),
  138. child: Column(
  139. crossAxisAlignment: CrossAxisAlignment.start,
  140. children: [
  141. Bone.text(width: 100),
  142. SizedBox(height: 4),
  143. Row(
  144. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  145. children: [
  146. Expanded(flex: 3, child: Bone.text()),
  147. const SizedBox(width: 8),
  148. Bone(width: 48, height: 20, borderRadius: BorderRadius.circular(4)),
  149. ],
  150. ),
  151. SizedBox(height: 4),
  152. Bone.text(),
  153. SizedBox(height: 4),
  154. Row(
  155. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  156. children: [
  157. Expanded(flex: 2, child: Bone.text()),
  158. const SizedBox(width: 8),
  159. Bone.text(width: 80),
  160. ],
  161. ),
  162. ],
  163. ),
  164. ),
  165. );
  166. }
  167. }
  168. /// 匹配公告卡片的骨架占位
  169. class SkeletonAnnouncementCard extends StatelessWidget {
  170. const SkeletonAnnouncementCard({super.key});
  171. @override
  172. Widget build(BuildContext context) {
  173. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  174. return Skeletonizer(
  175. enabled: true,
  176. child: Container(
  177. padding: const EdgeInsets.all(12),
  178. decoration: BoxDecoration(
  179. color: colors.bgCard,
  180. borderRadius: BorderRadius.circular(8),
  181. ),
  182. child: Column(
  183. crossAxisAlignment: CrossAxisAlignment.start,
  184. children: [
  185. Bone.text(),
  186. SizedBox(height: 8),
  187. Row(
  188. children: [
  189. Bone(width: 56, height: 20, borderRadius: BorderRadius.circular(4)),
  190. const SizedBox(width: 8),
  191. Bone.text(width: 60),
  192. const Spacer(),
  193. Bone.text(width: 120),
  194. ],
  195. ),
  196. ],
  197. ),
  198. ),
  199. );
  200. }
  201. }
  202. /// 匹配费用申请导入列表卡片的骨架占位
  203. class SkeletonImportCard extends StatelessWidget {
  204. const SkeletonImportCard({super.key});
  205. @override
  206. Widget build(BuildContext context) {
  207. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  208. return Skeletonizer(
  209. enabled: true,
  210. child: Container(
  211. padding: const EdgeInsets.fromLTRB(16, 12, 16, 8),
  212. decoration: BoxDecoration(
  213. color: colors.bgCard,
  214. borderRadius: BorderRadius.circular(12),
  215. ),
  216. child: Column(
  217. crossAxisAlignment: CrossAxisAlignment.start,
  218. children: [
  219. Row(
  220. children: [
  221. Bone.square(size: 22, borderRadius: BorderRadius.circular(4)),
  222. const SizedBox(width: 8),
  223. Expanded(flex: 3, child: Bone.text()),
  224. const Spacer(),
  225. Bone.text(width: 80),
  226. ],
  227. ),
  228. SizedBox(height: 8),
  229. Row(children: [const SizedBox(width: 30), Bone.text(width: 140)]),
  230. SizedBox(height: 8),
  231. Row(
  232. children: [
  233. Bone.square(size: 18, borderRadius: BorderRadius.circular(4)),
  234. const SizedBox(width: 4),
  235. Bone.text(width: 24),
  236. const SizedBox(width: 8),
  237. Expanded(flex: 3, child: Bone.text()),
  238. const Spacer(),
  239. Bone.text(width: 64),
  240. ],
  241. ),
  242. SizedBox(height: 8),
  243. Row(children: [const SizedBox(width: 54), Expanded(flex: 2, child: Bone.text())]),
  244. ],
  245. ),
  246. ),
  247. );
  248. }
  249. }
  250. /// 匹配消息卡片的骨架占位
  251. class SkeletonMessageCard extends StatelessWidget {
  252. const SkeletonMessageCard({super.key});
  253. @override
  254. Widget build(BuildContext context) {
  255. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  256. return Skeletonizer(
  257. enabled: true,
  258. child: Container(
  259. height: 88,
  260. padding: const EdgeInsets.all(12),
  261. decoration: BoxDecoration(
  262. color: colors.bgCard,
  263. borderRadius: BorderRadius.circular(8),
  264. ),
  265. child: Row(
  266. children: [
  267. Bone.circle(size: 40),
  268. SizedBox(width: 12),
  269. Expanded(
  270. child: Column(
  271. crossAxisAlignment: CrossAxisAlignment.start,
  272. children: [
  273. Row(
  274. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  275. children: [
  276. Expanded(flex: 3, child: Bone.text()),
  277. const Spacer(),
  278. Bone.text(width: 80),
  279. ],
  280. ),
  281. SizedBox(height: 2),
  282. Bone.text(width: 80),
  283. SizedBox(height: 2),
  284. Expanded(flex: 2, child: Bone.text()),
  285. ],
  286. ),
  287. ),
  288. SizedBox(width: 12),
  289. Bone(width: 8, height: 8, borderRadius: BorderRadius.circular(4)),
  290. ],
  291. ),
  292. ),
  293. );
  294. }
  295. }
  296. /// 详情页骨架(ExpenseDetailPage / ExpenseApplyDetailPage)
  297. /// 匹配 FormSection 卡片布局:基本信息 + 明细 + 附件
  298. class SkeletonDetailPage extends StatelessWidget {
  299. const SkeletonDetailPage({super.key});
  300. @override
  301. Widget build(BuildContext context) {
  302. return SingleChildScrollView(
  303. padding: const EdgeInsets.fromLTRB(16, 16, 16, 24),
  304. child: Skeletonizer(
  305. enabled: true,
  306. child: Column(
  307. children: [
  308. _FormCard(rows: 7),
  309. const SizedBox(height: 16),
  310. _FormCard(rows: 2),
  311. const SizedBox(height: 16),
  312. _FormCard(rows: 3),
  313. const SizedBox(height: 24),
  314. const Center(child: Bone(width: 120, height: 14)),
  315. ],
  316. ),
  317. ),
  318. );
  319. }
  320. }
  321. /// 表单页骨架(ExpenseApplyCreatePage / ExpenseCreatePage)
  322. /// 匹配 FormSection + 输入框 + 底部操作栏布局
  323. class SkeletonFormPage extends StatelessWidget {
  324. final bool showImportLink;
  325. const SkeletonFormPage({super.key, this.showImportLink = false});
  326. @override
  327. Widget build(BuildContext context) {
  328. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  329. final bottomPadding = MediaQuery.of(context).padding.bottom;
  330. return Stack(
  331. children: [
  332. SingleChildScrollView(
  333. padding: EdgeInsets.fromLTRB(16, 16, 16, 80 + bottomPadding),
  334. child: Skeletonizer(
  335. enabled: true,
  336. child: Column(
  337. children: [
  338. if (showImportLink) ...[
  339. // 导入申请单按钮骨架
  340. Container(
  341. padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
  342. decoration: BoxDecoration(
  343. color: colors.bgCard,
  344. borderRadius: BorderRadius.circular(12),
  345. ),
  346. child: Row(children: [
  347. Bone.square(size: 20, borderRadius: BorderRadius.circular(4)),
  348. const SizedBox(width: 8),
  349. Bone(width: 160, height: 14),
  350. ]),
  351. ),
  352. const SizedBox(height: 16),
  353. ],
  354. _FormCard(rows: 5),
  355. const SizedBox(height: 16),
  356. _FormCard(rows: 2),
  357. const SizedBox(height: 16),
  358. _FormCard(rows: 3),
  359. const SizedBox(height: 24),
  360. const Center(child: Bone(width: 120, height: 14)),
  361. ],
  362. ),
  363. ),
  364. ),
  365. // 底部操作栏骨架,贴底并适配安全区
  366. Positioned(
  367. left: 0, right: 0, bottom: 0,
  368. child: Skeletonizer(
  369. enabled: true,
  370. child: Container(
  371. padding: EdgeInsets.fromLTRB(16, 12, 16, 12 + bottomPadding),
  372. decoration: BoxDecoration(
  373. color: colors.bgCard,
  374. border: Border(top: BorderSide(color: colors.border)),
  375. ),
  376. child: Row(
  377. children: [
  378. Expanded(child: Bone(height: 44, borderRadius: BorderRadius.circular(8))),
  379. const SizedBox(width: 12),
  380. Expanded(child: Bone(height: 44, borderRadius: BorderRadius.circular(8))),
  381. ],
  382. ),
  383. ),
  384. ),
  385. ),
  386. ],
  387. );
  388. }
  389. }
  390. class _FormCard extends StatelessWidget {
  391. final int rows;
  392. const _FormCard({required this.rows});
  393. @override
  394. Widget build(BuildContext context) {
  395. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  396. return Container(
  397. padding: const EdgeInsets.all(16),
  398. decoration: BoxDecoration(
  399. color: colors.bgCard,
  400. borderRadius: BorderRadius.circular(12),
  401. ),
  402. child: Column(
  403. crossAxisAlignment: CrossAxisAlignment.start,
  404. children: [
  405. Row(children: [
  406. Bone.square(size: 20, borderRadius: BorderRadius.circular(4)),
  407. const SizedBox(width: 8),
  408. Bone(width: 80, height: 16),
  409. const Spacer(),
  410. Bone(width: 40, height: 16),
  411. ]),
  412. const SizedBox(height: 20),
  413. ...List.generate(rows, (i) => Padding(
  414. padding: EdgeInsets.only(bottom: i < rows - 1 ? 16 : 0),
  415. child: Row(
  416. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  417. children: [
  418. Bone(width: 64, height: 14),
  419. Bone(width: 140 + (i % 3) * 20, height: 14),
  420. ],
  421. ),
  422. )),
  423. ],
  424. ),
  425. );
  426. }
  427. }
  428. /// 报表页骨架(ExpenseDetailReportPage / ExpenseApplyDetailReportPage)
  429. /// 匹配 筛选栏 + 统计卡片(2x2) + 图表卡片 + 明细列表 布局
  430. class SkeletonReportPage extends StatelessWidget {
  431. const SkeletonReportPage({super.key});
  432. @override
  433. Widget build(BuildContext context) {
  434. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  435. return SingleChildScrollView(
  436. child: Skeletonizer(
  437. enabled: true,
  438. child: Column(
  439. children: [
  440. // 日期筛选栏
  441. Container(
  442. padding: const EdgeInsets.fromLTRB(12, 8, 12, 8),
  443. color: colors.bgCard,
  444. child: Row(children: [
  445. Expanded(child: Bone(height: 40, borderRadius: BorderRadius.circular(20))),
  446. const SizedBox(width: 8),
  447. Bone(width: 14, height: 14),
  448. const SizedBox(width: 8),
  449. Expanded(child: Bone(height: 40, borderRadius: BorderRadius.circular(20))),
  450. const SizedBox(width: 8),
  451. Bone(width: 40, height: 40, borderRadius: BorderRadius.circular(20)),
  452. ]),
  453. ),
  454. const SizedBox(height: 16),
  455. // 统计卡片 — 2行 x 2列
  456. Padding(
  457. padding: const EdgeInsets.symmetric(horizontal: 12),
  458. child: Column(children: [
  459. Row(children: [
  460. Expanded(child: Bone(height: 80, borderRadius: BorderRadius.circular(12))),
  461. const SizedBox(width: 8),
  462. Expanded(child: Bone(height: 80, borderRadius: BorderRadius.circular(12))),
  463. ]),
  464. const SizedBox(height: 8),
  465. Row(children: [
  466. Expanded(child: Bone(height: 80, borderRadius: BorderRadius.circular(12))),
  467. const SizedBox(width: 8),
  468. Expanded(child: Bone(height: 80, borderRadius: BorderRadius.circular(12))),
  469. ]),
  470. ]),
  471. ),
  472. const SizedBox(height: 16),
  473. // 图表卡片 — 标题 + 图表区
  474. Padding(
  475. padding: const EdgeInsets.symmetric(horizontal: 12),
  476. child: Container(
  477. padding: const EdgeInsets.all(16),
  478. decoration: BoxDecoration(color: colors.bgCard, borderRadius: BorderRadius.circular(12)),
  479. child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
  480. Row(children: [Bone.square(size: 20, borderRadius: BorderRadius.circular(4)), const SizedBox(width: 8), Bone(width: 120, height: 16)]),
  481. const SizedBox(height: 16),
  482. Bone(height: 200, borderRadius: BorderRadius.circular(8)),
  483. ]),
  484. ),
  485. ),
  486. const SizedBox(height: 16),
  487. // 明细列表卡片 — 表头 + 行
  488. Padding(
  489. padding: const EdgeInsets.symmetric(horizontal: 12),
  490. child: Container(
  491. padding: const EdgeInsets.all(16),
  492. decoration: BoxDecoration(color: colors.bgCard, borderRadius: BorderRadius.circular(12)),
  493. child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
  494. Row(children: [Bone.square(size: 20, borderRadius: BorderRadius.circular(4)), const SizedBox(width: 8), Bone(width: 80, height: 16)]),
  495. const SizedBox(height: 16),
  496. ...List.generate(6, (_) => Padding(
  497. padding: const EdgeInsets.only(bottom: 8),
  498. child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
  499. Bone(width: 60, height: 14),
  500. Bone(width: 100, height: 14),
  501. Bone(width: 80, height: 14),
  502. Bone(width: 60, height: 14),
  503. ]),
  504. )),
  505. ]),
  506. ),
  507. ),
  508. const SizedBox(height: 24),
  509. ],
  510. ),
  511. ),
  512. );
  513. }
  514. }