title.dart 1.28 KB
Newer Older
Adam Barth's avatar
Adam Barth committed
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 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
7

8
/// A widget that describes this app in the operating system.
9
class Title extends StatelessWidget {
10
  /// Creates a widget that describes this app to the operating system.
11 12 13
  Title({
    Key key,
    this.title,
14 15
    this.color,
    this.child
16
  }) : super(key: key) {
Ian Hickson's avatar
Ian Hickson committed
17 18
    assert(color == null || color.alpha == 0xFF);
  }
Adam Barth's avatar
Adam Barth committed
19

20
  /// A one-line description of this app for use in the window manager.
Adam Barth's avatar
Adam Barth committed
21
  final String title;
22 23

  /// A color that the window manager should use to identify this app.
24
  final Color color;
Adam Barth's avatar
Adam Barth committed
25

26
  /// The widget below this widget in the tree.
27 28
  final Widget child;

29
  @override
30
  Widget build(BuildContext context) {
31 32 33 34 35 36
    SystemChrome.setApplicationSwitcherDescription(
      new ApplicationSwitcherDescription(
        label: title,
        primaryColor: color.value,
      )
    );
Adam Barth's avatar
Adam Barth committed
37 38
    return child;
  }
Hixie's avatar
Hixie committed
39

40
  @override
Hixie's avatar
Hixie committed
41 42
  void debugFillDescription(List<String> description) {
    super.debugFillDescription(description);
Ian Hickson's avatar
Ian Hickson committed
43 44 45 46
    if (title != null)
      description.add('"$title"');
    if (color != null)
      description.add('color: $color');
Hixie's avatar
Hixie committed
47
  }
Adam Barth's avatar
Adam Barth committed
48
}