简体   繁体   中英

Flutter ColorFiltered Widget with Text widget

I'm using the ColorFiltered widget to grey out widgets that are disabled for a reason.

The ColorFiltered widget works well with images, but it won't change the Text widget color.

Is that a way to grey out images and Text widgets at once?

The following is my ' DisableWidget '

class DisableWidget extends StatelessWidget {
  final Widget child;
  final bool disable;
  const DisableWidget({
    Key key,
    this.child,
    this.disable = false,
  }) : super(key: key);

  Widget build(BuildContext context) {
    return disable
        ? ColorFiltered(
            colorFilter: ColorFilter.mode(Colors.grey, BlendMode.saturation),
            child: AbsorbPointer(absorbing: true, ignoringSemantics: true, child: child),
          )
        : child;
  }
}

I managed to do it by wrapping the ColorFiltered with Opacity widget.

Here is my final DisableWidget .

class DisableWidget extends StatelessWidget {
  final Widget child;
  final bool disable;
  const DisableWidget({
    Key key,
    this.child,
    this.disable = false,
  }) : super(key: key);

  Widget build(BuildContext context) {
    return disable
        ? Opacity(
            opacity: 0.5,
            child: ColorFiltered(
              colorFilter: ColorFilter.mode(Colors.grey, BlendMode.saturation),
              child: AbsorbPointer(
                absorbing: true,
                ignoringSemantics: true,
                child: child,
              ),
            ),
          )
        : child;
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM