image.dart 1.2 KB

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