image.dart 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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({
  8. super.key,
  9. required this.name,
  10. this.size,
  11. this.color,
  12. });
  13. final String name;
  14. final Size? size;
  15. final Color? color;
  16. @override
  17. Widget build(BuildContext context) {
  18. return svgWidget(
  19. name,
  20. size: size,
  21. color: color ?? Theme.of(context).iconTheme.color,
  22. );
  23. }
  24. }
  25. Widget svgWidget(String name, {Size? size, Color? color}) {
  26. if (size != null) {
  27. return SizedBox.fromSize(
  28. size: size,
  29. child: SvgPicture.asset(
  30. 'assets/images/$name.svg',
  31. colorFilter:
  32. color != null ? ColorFilter.mode(color, BlendMode.srcIn) : null,
  33. ),
  34. );
  35. } else {
  36. return SvgPicture.asset(
  37. 'assets/images/$name.svg',
  38. colorFilter:
  39. color != null ? ColorFilter.mode(color, BlendMode.srcIn) : null,
  40. );
  41. }
  42. }