image.dart 1014 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_svg/flutter_svg.dart';
  3. /// For icon that needs to change color when it is on hovered
  4. ///
  5. /// Get the hover color from ThemeData
  6. class FlowySvg extends StatelessWidget {
  7. const FlowySvg({super.key, this.size, required this.name});
  8. final String name;
  9. final Size? size;
  10. @override
  11. Widget build(BuildContext context) {
  12. return svgWidget(
  13. 'assets/images/$name.svg',
  14. size: size,
  15. color: Theme.of(context).iconTheme.color,
  16. );
  17. }
  18. }
  19. Widget svgWidget(String name, {Size? size, Color? color}) {
  20. if (size != null) {
  21. return SizedBox.fromSize(
  22. size: size,
  23. child: SvgPicture.asset(
  24. 'assets/images/$name.svg',
  25. colorFilter:
  26. color != null ? ColorFilter.mode(color, BlendMode.srcIn) : null,
  27. ),
  28. );
  29. } else {
  30. return SvgPicture.asset(
  31. 'assets/images/$name.svg',
  32. colorFilter:
  33. color != null ? ColorFilter.mode(color, BlendMode.srcIn) : null,
  34. );
  35. }
  36. }