auto_layout.dart 1.29 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
  RenderAutoLayout createRenderObject(BuildContext context) => new RenderAutoLayout(delegate: delegate);
23

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

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

33
  final AutoLayoutRect rect;
34 35 36 37 38 39

  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.
40
    parentData.rect = rect;
41 42
  }
}