widget_extension.dart 908 B

123456789101112131415161718192021222324252627282930313233343536
  1. import 'package:flutter/widgets.dart';
  2. extension WidgetDesktopX on Widget {
  3. /// 仅在桌面端添加点击手势光标
  4. Widget withClickCursor(bool isDesktop) {
  5. if (isDesktop) {
  6. return MouseRegion(cursor: SystemMouseCursors.click, child: this);
  7. }
  8. return this;
  9. }
  10. }
  11. extension WidgetShadowX on Widget {
  12. /// 为 Widget 添加自定义阴影
  13. Widget withShadow({
  14. Color shadowColor = const Color(0xFF000000),
  15. double opacity = 0.18,
  16. double blurRadius = 3.0,
  17. Offset offset = const Offset(1, 1),
  18. double borderRadius = 0.0,
  19. }) {
  20. return Container(
  21. decoration: BoxDecoration(
  22. borderRadius: BorderRadius.circular(borderRadius),
  23. boxShadow: [
  24. BoxShadow(
  25. color: shadowColor.withOpacity(opacity),
  26. blurRadius: blurRadius,
  27. offset: offset,
  28. ),
  29. ],
  30. ),
  31. child: this,
  32. );
  33. }
  34. }