"Fossies" - the Fresh Open Source Software Archive

Member "flutter-1.22.4/packages/flutter/lib/src/widgets/color_filter.dart" (13 Nov 2020, 1916 Bytes) of package /linux/misc/flutter-1.22.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Dart source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // Copyright 2014 The Flutter Authors. All rights reserved.
    2 // Use of this source code is governed by a BSD-style license that can be
    3 // found in the LICENSE file.
    4 
    5 // @dart = 2.8
    6 
    7 import 'dart:ui';
    8 
    9 import 'package:flutter/foundation.dart';
   10 import 'package:flutter/rendering.dart';
   11 
   12 import 'framework.dart';
   13 
   14 /// Applies a [ColorFilter] to its child.
   15 ///
   16 /// {@youtube 560 315 https://www.youtube.com/watch?v=F7Cll22Dno8}
   17 @immutable
   18 class ColorFiltered extends SingleChildRenderObjectWidget {
   19   /// Creates a widget that applies a [ColorFilter] to its child.
   20   ///
   21   /// The [colorFilter] must not be null.
   22   const ColorFiltered({@required this.colorFilter, Widget child, Key key})
   23       : assert(colorFilter != null),
   24         super(key: key, child: child);
   25 
   26   /// The color filter to apply to the child of this widget.
   27   final ColorFilter colorFilter;
   28 
   29   @override
   30   RenderObject createRenderObject(BuildContext context) => _ColorFilterRenderObject(colorFilter);
   31 
   32   @override
   33   void updateRenderObject(BuildContext context, _ColorFilterRenderObject renderObject) {
   34     renderObject.colorFilter = colorFilter;
   35   }
   36 
   37   @override
   38   void debugFillProperties(DiagnosticPropertiesBuilder properties) {
   39     super.debugFillProperties(properties);
   40     properties.add(DiagnosticsProperty<ColorFilter>('colorFilter', colorFilter));
   41   }
   42 }
   43 
   44 class _ColorFilterRenderObject extends RenderProxyBox {
   45   _ColorFilterRenderObject(this._colorFilter);
   46 
   47   ColorFilter get colorFilter => _colorFilter;
   48   ColorFilter _colorFilter;
   49   set colorFilter(ColorFilter value) {
   50     assert(value != null);
   51     if (value != _colorFilter) {
   52       _colorFilter = value;
   53       markNeedsPaint();
   54     }
   55   }
   56 
   57   @override
   58   bool get alwaysNeedsCompositing => child != null;
   59 
   60   @override
   61   void paint(PaintingContext context, Offset offset) {
   62     layer = context.pushColorFilter(offset, colorFilter, super.paint, oldLayer: layer as ColorFilterLayer);
   63   }
   64 }