title.dart 1.78 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
Adam Barth's avatar
Adam Barth committed
2 3 4
// 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
  Title({
19
    Key? key,
20
    this.title = '',
21 22
    required this.color,
    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.ProxyWidget.child}
39 40
  final Widget child;

41
  @override
42
  Widget build(BuildContext context) {
43
    SystemChrome.setApplicationSwitcherDescription(
44
      ApplicationSwitcherDescription(
45 46
        label: title,
        primaryColor: color.value,
47
      ),
48
    );
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
    properties.add(StringProperty('title', title, defaultValue: ''));
56
    properties.add(ColorProperty('color', color, defaultValue: null));
Hixie's avatar
Hixie committed
57
  }
Adam Barth's avatar
Adam Barth committed
58
}