placeholder.dart 1.07 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
  /// Creates a widget whose child can be mutated.
11 12
  Placeholder({ Key key }) : super(key: key);

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

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

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