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 | import 'package:flutter/rendering.dart'; |
6 | |
7 | import 'framework.dart'; |
8 | |
9 | /// Annotates a region of the layer tree with a value. |
10 | /// |
11 | /// See also: |
12 | /// |
13 | /// * [Layer.find], for an example of how this value is retrieved. |
14 | /// * [AnnotatedRegionLayer], the layer pushed into the layer tree. |
15 | class AnnotatedRegion<T extends Object> extends SingleChildRenderObjectWidget { |
16 | /// Creates a new annotated region to insert [value] into the layer tree. |
17 | /// |
18 | /// Neither [child] nor [value] may be null. |
19 | /// |
20 | /// [sized] defaults to true and controls whether the annotated region will |
21 | /// clip its child. |
22 | const AnnotatedRegion({ |
23 | super.key, |
24 | required Widget super.child, |
25 | required this.value, |
26 | this.sized = true, |
27 | }); |
28 | |
29 | /// A value which can be retrieved using [Layer.find]. |
30 | final T value; |
31 | |
32 | /// If false, the layer pushed into the tree will not be provided with a size. |
33 | /// |
34 | /// An [AnnotatedRegionLayer] with a size checks that the offset provided in |
35 | /// [Layer.find] is within the bounds, returning null otherwise. |
36 | /// |
37 | /// See also: |
38 | /// |
39 | /// * [AnnotatedRegionLayer], for a description of this behavior. |
40 | final bool sized; |
41 | |
42 | @override |
43 | RenderObject createRenderObject(BuildContext context) { |
44 | return RenderAnnotatedRegion<T>(value: value, sized: sized); |
45 | } |
46 | |
47 | @override |
48 | void updateRenderObject(BuildContext context, RenderAnnotatedRegion<T> renderObject) { |
49 | renderObject |
50 | ..value = value |
51 | ..sized = sized; |
52 | } |
53 | } |
54 | |