title.dart 1.75 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
    super.key,
20
    this.title = '',
21 22
    required this.color,
    required this.child,
23
  }) : assert(title != null),
24
       assert(color != null && color.alpha == 0xFF);
Adam Barth's avatar
Adam Barth committed
25

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

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

35
  /// The widget below this widget in the tree.
36
  ///
37
  /// {@macro flutter.widgets.ProxyWidget.child}
38 39
  final Widget child;

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

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