skeleton_list_card.dart 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. }