my_card.dart 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import 'package:flutter/material.dart';
  2. class MyCard extends StatelessWidget {
  3. const MyCard({Key key, @required this.child, this.color, this.shadowColor})
  4. : super(key: key);
  5. final Widget child;
  6. final Color color;
  7. final Color shadowColor;
  8. @override
  9. Widget build(BuildContext context) {
  10. Color _backgroundColor;
  11. Color _shadowColor;
  12. if (color == null) {
  13. _backgroundColor = Colors.white;
  14. } else {
  15. _backgroundColor = color;
  16. }
  17. if (shadowColor == null) {
  18. _shadowColor = const Color(0x80DCE7FA);
  19. } else {
  20. _shadowColor = shadowColor;
  21. }
  22. return Card(
  23. // margin: EdgeInsets.all(ScreenUtil().setWidth(10)),
  24. //设置圆角度,也可以不设置有默认值
  25. shape: RoundedRectangleBorder(
  26. //形状
  27. //修改圆角
  28. borderRadius: BorderRadius.all(Radius.circular(10)),
  29. ),
  30. //阴影颜色
  31. color: color,
  32. //阴影高度
  33. elevation: 0.5,
  34. child: ClipRRect(
  35. borderRadius: BorderRadius.all(Radius.circular(10)), child: child),
  36. );
  37. // DecoratedBox(
  38. // decoration: BoxDecoration(
  39. // color: _backgroundColor,
  40. // borderRadius: BorderRadius.circular(10.0),
  41. // boxShadow: [
  42. // BoxShadow(color: _shadowColor, offset: Offset(0.0, 2.0), blurRadius: 8.0, spreadRadius: 0.0),
  43. // ]
  44. // ),
  45. // child: child,
  46. // );
  47. }
  48. }