app_card.dart 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import 'package:flutter/material.dart';
  2. import '../../utils/constants.dart';
  3. /// 应用卡片组件
  4. class AppCard extends StatelessWidget {
  5. final Widget? title;
  6. final List<Widget>? actions;
  7. final Widget child;
  8. final EdgeInsets? padding;
  9. final EdgeInsets? margin;
  10. final bool hoverable;
  11. final VoidCallback? onTap;
  12. const AppCard({
  13. Key? key,
  14. this.title,
  15. this.actions,
  16. required this.child,
  17. this.padding,
  18. this.margin,
  19. this.hoverable = false,
  20. this.onTap,
  21. }) : super(key: key);
  22. @override
  23. Widget build(BuildContext context) {
  24. Widget card = Card(
  25. elevation: 2,
  26. shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
  27. margin: margin ?? const EdgeInsets.all(0),
  28. child: Column(
  29. crossAxisAlignment: CrossAxisAlignment.start,
  30. mainAxisSize: MainAxisSize.min,
  31. children: [
  32. if (title != null || actions != null)
  33. Padding(
  34. padding: EdgeInsets.fromLTRB(
  35. AppSpacing.md,
  36. AppSpacing.md,
  37. AppSpacing.sm,
  38. title != null ? AppSpacing.sm : AppSpacing.md,
  39. ),
  40. child: Row(
  41. children: [
  42. if (title != null) Expanded(child: title!),
  43. if (actions != null) ...actions!,
  44. ],
  45. ),
  46. ),
  47. Padding(
  48. padding:
  49. padding ?? EdgeInsets.all(title != null ? 0 : AppSpacing.md),
  50. child: child,
  51. ),
  52. ],
  53. ),
  54. );
  55. if (onTap != null) {
  56. card = InkWell(
  57. onTap: onTap,
  58. borderRadius: BorderRadius.circular(8),
  59. child: card,
  60. );
  61. }
  62. if (hoverable) {
  63. card = MouseRegion(
  64. cursor:
  65. onTap != null ? SystemMouseCursors.click : SystemMouseCursors.basic,
  66. child: card,
  67. );
  68. }
  69. return card;
  70. }
  71. }