placeholder.dart 1023 Bytes
Newer Older
1 2 3 4
// 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.

5 6
import 'basic.dart';
import 'framework.dart';
7

8
/// A widget whose child can be mutated.
9 10 11 12 13 14
class Placeholder extends StatefulComponent {
  Placeholder({ Key key }) : super(key: key);

  PlaceholderState createState() => new PlaceholderState();
}

Adam Barth's avatar
Adam Barth committed
15 16 17
/// State for a [Placeholder] widget.
///
/// Useful for setting the child currently displayed by this placeholder widget.
18
class PlaceholderState extends State<Placeholder> {
19 20 21
  /// The child that this widget builds.
  ///
  /// Mutating this field will cause this widget to rebuild with the new child.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
  Widget get child => _child;
  Widget _child;
  void set child(Widget child) {
    if (_child == child)
      return;
    setState(() {
      _child = child;
    });
  }

  Widget build(BuildContext context) {
    if (_child != null)
      return child;
    return new SizedBox(width: 0.0, height: 0.0);
  }
}