title.dart 1.74 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
import 'package:flutter/foundation.dart';
6
import 'package:flutter/services.dart';
7 8 9

import 'basic.dart';
import 'framework.dart';
10

11
/// A widget that describes this app in the operating system.
12
class Title extends StatelessWidget {
13
  /// Creates a widget that describes this app to the operating system.
14 15 16 17
  ///
  /// [title] will default to the empty string if not supplied.
  /// [color] must be an opaque color (i.e. color.alpha must be 255 (0xFF)).
  /// [color] and [child] are required arguments.
18 19
  Title({
    Key key,
20 21
    this.title: '',
    @required this.color,
22
    @required this.child,
23 24
  }) : assert(title != null),
       assert(color != null && color.alpha == 0xFF),
25
       super(key: key);
Adam Barth's avatar
Adam Barth committed
26

27
  /// A one-line description of this app for use in the window manager.
28
  /// Must not be null.
Adam Barth's avatar
Adam Barth committed
29
  final String title;
30

31 32 33
  /// A color that the window manager should use to identify this app.  Must be
  /// an opaque color (i.e. color.alpha must be 255 (0xFF)), and must not be
  /// null.
34
  final Color color;
Adam Barth's avatar
Adam Barth committed
35

36
  /// The widget below this widget in the tree.
37 38
  final Widget child;

39
  @override
40
  Widget build(BuildContext context) {
41 42 43 44 45 46
    SystemChrome.setApplicationSwitcherDescription(
      new ApplicationSwitcherDescription(
        label: title,
        primaryColor: color.value,
      )
    );
Adam Barth's avatar
Adam Barth committed
47 48
    return child;
  }
Hixie's avatar
Hixie committed
49

50
  @override
51
  void debugFillProperties(DiagnosticPropertiesBuilder description) {
52
    super.debugFillProperties(description);
53
    description.add(new StringProperty('title', title, defaultValue: ''));
54
    description.add(new DiagnosticsProperty<Color>('color', color, defaultValue: null));
Hixie's avatar
Hixie committed
55
  }
Adam Barth's avatar
Adam Barth committed
56
}