title.dart 1.78 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 Android 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
    this.title = '',
21
    @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
  /// A color that the window manager should use to identify this app. Must be
32 33
  /// 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
  ///
  /// {@macro flutter.widgets.child}
39 40
  final Widget child;

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

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