blob: cad96a2ee1d1f6c2e15dd656781c95dff743f3e9 [file] [log] [blame]
// Copyright 2019 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ui';
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'framework.dart';
/// Applies a [ColorFilter] to its child.
class ColorFiltered extends SingleChildRenderObjectWidget {
/// Creates a widget that applies a [ColorFilter] to its child.
/// The [colorFilter] must not be null.
const ColorFiltered({@required this.colorFilter, Widget child, Key key})
: assert(colorFilter != null),
super(key: key, child: child);
/// The color filter to apply to the child of this widvget.
final ColorFilter colorFilter;
RenderObject createRenderObject(BuildContext context) => _ColorFilterRenderObject(colorFilter);
void updateRenderObject(BuildContext context, _ColorFilterRenderObject renderObject) {
renderObject..colorFilter = colorFilter;
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
properties.add(DiagnosticsProperty<ColorFilter>('colorFilter', colorFilter));
class _ColorFilterRenderObject extends RenderProxyBox {
ColorFilter get colorFilter => _colorFilter;
ColorFilter _colorFilter;
set colorFilter(ColorFilter value) {
assert(value != null);
if (value != _colorFilter) {
_colorFilter = value;
bool get alwaysNeedsCompositing => child != null;
void paint(PaintingContext context, Offset offset) {
layer = context.pushColorFilter(offset, colorFilter, super.paint, oldLayer: layer);