child_view.dart 1.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Copyright 2016 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 'media_query.dart';
import 'framework.dart';

export 'package:flutter/rendering.dart' show ChildViewConnection;

class ChildView extends StatelessComponent {
  ChildView({ Key key, this.child }) : super(key: key);

  final ChildViewConnection child;

  Widget build(BuildContext context) {
18
    assert(MediaQuery.of(context) != null);
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
    return new _ChildViewWidget(
      child: child,
      scale: MediaQuery.of(context).devicePixelRatio
    );
  }
}

class _ChildViewWidget extends LeafRenderObjectWidget {
  _ChildViewWidget({
    ChildViewConnection child,
    this.scale
  }) : child = child, super(key: new GlobalObjectKey(child));

  final ChildViewConnection child;
  final double scale;

  RenderChildView createRenderObject() => new RenderChildView(child: child, scale: scale);

  void updateRenderObject(RenderChildView renderObject, _ChildViewWidget oldWidget) {
    renderObject
      ..child = child
      ..scale = scale;
  }
}