app_shimmer.dart 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import 'package:flutter/material.dart';
  2. import 'package:shimmer/shimmer.dart';
  3. /// 通用 Shimmer 包装器,与首页保持一致的 baseColor / highlightColor
  4. class AppShimmer extends StatelessWidget {
  5. const AppShimmer({super.key, required this.child});
  6. final Widget child;
  7. @override
  8. Widget build(BuildContext context) {
  9. final cs = Theme.of(context).colorScheme;
  10. return Shimmer.fromColors(
  11. baseColor: cs.onSurface.withAlpha(15),
  12. highlightColor: cs.onSurface.withAlpha(30),
  13. child: child,
  14. );
  15. }
  16. }
  17. /// 圆角矩形占位块
  18. Widget shimmerBox(double width, double height, {double radius = 4}) {
  19. return Container(
  20. width: width,
  21. height: height,
  22. decoration: BoxDecoration(
  23. color: Colors.white,
  24. borderRadius: BorderRadius.circular(radius),
  25. ),
  26. );
  27. }
  28. /// 圆形占位块
  29. Widget shimmerCircle(double size) {
  30. return Container(
  31. width: size,
  32. height: size,
  33. decoration: const BoxDecoration(
  34. color: Colors.white,
  35. shape: BoxShape.circle,
  36. ),
  37. );
  38. }
  39. /// 通用"填满宽度"占位块(width = double.infinity)
  40. Widget shimmerFill(double height, {double radius = 4, EdgeInsets? margin}) {
  41. return Container(
  42. margin: margin,
  43. height: height,
  44. decoration: BoxDecoration(
  45. color: Colors.white,
  46. borderRadius: BorderRadius.circular(radius),
  47. ),
  48. );
  49. }