auto_layout.dart 1.32 KB
Newer Older
1 2 3 4 5 6 7 8 9
// Copyright 2015 The Chromium 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 'package:flutter/rendering.dart';

import 'framework.dart';

export 'package:flutter/rendering.dart' show
10
    AutoLayoutRect,
11 12 13 14 15 16 17 18 19 20 21
    AutoLayoutDelegate;

class AutoLayout extends MultiChildRenderObjectWidget {
  AutoLayout({
    Key key,
    this.delegate,
    List<Widget> children: const <Widget>[]
  }) : super(key: key, children: children);

  final AutoLayoutDelegate delegate;

22
  @override
23
  RenderAutoLayout createRenderObject(BuildContext context) => new RenderAutoLayout(delegate: delegate);
24

25
  @override
26
  void updateRenderObject(BuildContext context, RenderAutoLayout renderObject) {
27 28 29 30 31
    renderObject.delegate = delegate;
  }
}

class AutoLayoutChild extends ParentDataWidget<AutoLayout> {
32 33
  AutoLayoutChild({ AutoLayoutRect rect, Widget child })
    : rect = rect, super(key: new ObjectKey(rect), child: child);
34

35
  final AutoLayoutRect rect;
36

37
  @override
38 39 40 41 42
  void applyParentData(RenderObject renderObject) {
    assert(renderObject.parentData is AutoLayoutParentData);
    final AutoLayoutParentData parentData = renderObject.parentData;
    // AutoLayoutParentData filters out redundant writes and marks needs layout
    // as appropriate.
43
    parentData.rect = rect;
44 45
  }
}