title.dart 1.71 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(color.alpha == 0xFF);
Adam Barth's avatar
Adam Barth committed
24

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

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

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

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

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