surface_card.dart 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import 'package:flutter/material.dart';
  2. import '../theme/app_colors.dart';
  3. /// The soft paper-like card used for the volume control, shortcuts and
  4. /// settings sections.
  5. class SurfaceCard extends StatelessWidget {
  6. const SurfaceCard({
  7. super.key,
  8. required this.child,
  9. this.padding = const EdgeInsets.all(24),
  10. this.radius = 28,
  11. this.color,
  12. this.borderColor,
  13. this.showShadow = true,
  14. this.onTap,
  15. });
  16. final Widget child;
  17. final EdgeInsetsGeometry padding;
  18. final double radius;
  19. final Color? color;
  20. final Color? borderColor;
  21. final bool showShadow;
  22. final VoidCallback? onTap;
  23. @override
  24. Widget build(BuildContext context) {
  25. final colors = context.colors;
  26. final isDark = Theme.of(context).brightness == Brightness.dark;
  27. final decoration = BoxDecoration(
  28. color: color ?? colors.surface,
  29. borderRadius: BorderRadius.circular(radius),
  30. border: Border.all(color: borderColor ?? colors.border),
  31. boxShadow: showShadow
  32. ? [
  33. BoxShadow(
  34. color: colors.shadow.withValues(alpha: isDark ? 0.24 : 0.045),
  35. blurRadius: isDark ? 28 : 30,
  36. offset: const Offset(0, 12),
  37. ),
  38. ]
  39. : null,
  40. );
  41. final content = Container(
  42. padding: padding,
  43. decoration: decoration,
  44. child: child,
  45. );
  46. if (onTap == null) return content;
  47. return Material(
  48. color: Colors.transparent,
  49. child: InkWell(
  50. onTap: onTap,
  51. borderRadius: BorderRadius.circular(radius),
  52. child: content,
  53. ),
  54. );
  55. }
  56. }