flutter_logo.dart 2.53 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/widgets.dart';

/// The Flutter logo, in widget form. This widget respects the [IconTheme].
8
/// For guidelines on using the Flutter logo, visit https://flutter.dev/brand.
9 10 11 12 13 14 15 16 17
///
/// See also:
///
///  * [IconTheme], which provides ambient configuration for icons.
///  * [Icon], for showing icons the Material design icon library.
///  * [ImageIcon], for showing icons from [AssetImage]s or other [ImageProvider]s.
class FlutterLogo extends StatelessWidget {
  /// Creates a widget that paints the Flutter logo.
  ///
18
  /// The [size] defaults to the value given by the current [IconTheme].
19 20 21
  ///
  /// The [textColor], [style], [duration], and [curve] arguments must not be
  /// null.
22
  const FlutterLogo({
23
    Key? key,
24
    this.size,
25
    this.textColor = const Color(0xFF757575),
26 27 28
    this.style = FlutterLogoStyle.markOnly,
    this.duration = const Duration(milliseconds: 750),
    this.curve = Curves.fastOutSlowIn,
29 30 31 32 33
  }) : assert(textColor != null),
       assert(style != null),
       assert(duration != null),
       assert(curve != null),
       super(key: key);
34 35 36 37 38 39 40 41

  /// The size of the logo in logical pixels.
  ///
  /// The logo will be fit into a square this size.
  ///
  /// Defaults to the current [IconTheme] size, if any. If there is no
  /// [IconTheme], or it does not specify an explicit size, then it defaults to
  /// 24.0.
42
  final double? size;
43

44
  /// The color used to paint the "Flutter" text on the logo, if [style] is
45 46 47 48
  /// [FlutterLogoStyle.horizontal] or [FlutterLogoStyle.stacked].
  ///
  /// If possible, the default (a medium grey) should be used against a white
  /// background.
49 50
  final Color textColor;

51 52 53 54
  /// Whether and where to draw the "Flutter" text. By default, only the logo
  /// itself is drawn.
  final FlutterLogoStyle style;

55 56
  /// The length of time for the animation if the [style] or [textColor]
  /// properties are changed.
57 58
  final Duration duration;

59
  /// The curve for the logo animation if the [style] or [textColor] change.
60 61
  final Curve curve;

62 63
  @override
  Widget build(BuildContext context) {
64
    final IconThemeData iconTheme = IconTheme.of(context);
65
    final double? iconSize = size ?? iconTheme.size;
66
    return AnimatedContainer(
67 68 69
      width: iconSize,
      height: iconSize,
      duration: duration,
70
      curve: curve,
71
      decoration: FlutterLogoDecoration(
72
        style: style,
73
        textColor: textColor,
74 75 76 77
      ),
    );
  }
}