flutter_svg icon indicating copy to clipboard operation
flutter_svg copied to clipboard

ColorFilter being applied to whole app instead of just the SVG

Open wilsonsilva opened this issue 1 year ago • 6 comments

My ColorFilter is being applied to the whole app, not just the container of the SVG. I tried wrapping the SVG in a Container and other widgets but it still applies the filter to the whole app. Is this expected?

Screenshot 2023-07-08 at 19 12 21

Code:

import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

void main() {
  runApp(App());
}

class App extends StatelessWidget {
  App({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Center(
          child: SizedBox(
            width: 300,
            height: 300,
            child: SvgPicture.asset(
              'assets/svg/dart.svg', // from flutter_svg/example/assets/dart.svg
              colorFilter: const ColorFilter.mode(
                Color(0xFFFFC555),
                BlendMode.hardLight,
              ),
            ),
          ),
        ),
      )
    );
  }
}
FlutterSvg 2.0.7

Flutter 3.10.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 796c8ef792 (4 weeks ago) • 2023-06-13 15:51:02 -0700
Engine • revision 45f6e00911
Tools • Dart 3.0.5 • DevTools 2.23.1

wilsonsilva avatar Jul 08 '23 12:07 wilsonsilva

This also happens in the example app.

Screenshot 2023-07-09 at 08 38 43

wilsonsilva avatar Jul 09 '23 01:07 wilsonsilva

Could be related to #942 or #938? What happens if you try ColorFilter.mode(Colors.transparent, BlendMode.srcATop). If that works maybe you can cast the Color(0xFFFFC555) backdrop with a widget behind the SvgPicture. I was able to work around my problem while still staying with impeller that way.

MrCsabaToth avatar Jul 15 '23 21:07 MrCsabaToth

This bit me as well. As an extra data point, it only started after I upgraded from Flutter 3.10.x to Flutter 3.13.0. Using the ColorFiltered widget (wrapping SvgPicture) works around the issue for me.

noinskit avatar Aug 17 '23 09:08 noinskit

try BlendMode.srcIn

  colorFilter: const ColorFilter.mode(
                MainColors.color2,
                BlendMode.srcIn,
              ),

Mohdx avatar Oct 04 '23 03:10 Mohdx

Still happening to me. In my case I was trying to set the image to grayscale:

                                                  SvgPicture.asset(
                                                      'assets/images/svg/undraw_profile_pic_ic5t.svg',
                                                      semanticsLabel: 'Profile pic',
                                                      colorFilter: const ColorFilter.mode(
                                                        Colors.grey,
                                                        BlendMode.saturation,
                                                      ),
                                                    ),

minhdanh avatar May 15 '24 01:05 minhdanh

I don't know if this is related, but for me all color filters, except for modulate would dye even the transparent parts of my SVG.

martin-braun avatar May 28 '24 02:05 martin-braun