annotated_region.dart 1.64 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7 8 9 10 11 12
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/rendering.dart';

import 'framework.dart';

/// Annotates a region of the layer tree with a value.
///
/// See also:
///
13 14
///  * [Layer.find], for an example of how this value is retrieved.
///  * [AnnotatedRegionLayer], the layer pushed into the layer tree.
15
class AnnotatedRegion<T extends Object> extends SingleChildRenderObjectWidget {
16 17 18 19 20 21 22
  /// Creates a new annotated region to insert [value] into the layer tree.
  ///
  /// Neither [child] nor [value] may be null.
  ///
  /// [sized] defaults to true and controls whether the annotated region will
  /// clip its child.
  const AnnotatedRegion({
23 24
    super.key,
    required Widget super.child,
25
    required this.value,
26 27
    this.sized = true,
  }) : assert(value != null),
28
       assert(child != null);
29 30 31 32 33 34 35 36 37 38 39

  /// A value which can be retrieved using [Layer.find].
  final T value;

  /// If false, the layer pushed into the tree will not be provided with a size.
  ///
  /// An [AnnotatedRegionLayer] with a size checks that the offset provided in
  /// [Layer.find] is within the bounds, returning null otherwise.
  ///
  /// See also:
  ///
40
  ///  * [AnnotatedRegionLayer], for a description of this behavior.
41 42 43 44
  final bool sized;

  @override
  RenderObject createRenderObject(BuildContext context) {
45
    return RenderAnnotatedRegion<T>(value: value, sized: sized);
46 47 48 49 50 51 52 53 54
  }

  @override
  void updateRenderObject(BuildContext context, RenderAnnotatedRegion<T> renderObject) {
    renderObject
      ..value = value
      ..sized = sized;
  }
}