placeholder.dart 1.01 KB
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
class Placeholder extends StatefulWidget {
10 11
  Placeholder({ Key key }) : super(key: key);

12
  @override
13 14 15
  PlaceholderState createState() => new PlaceholderState();
}

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

33
  @override
34 35 36 37 38 39
  Widget build(BuildContext context) {
    if (_child != null)
      return child;
    return new SizedBox(width: 0.0, height: 0.0);
  }
}