flutter_logo.dart 2.58 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
/// {@youtube 560 315 https://www.youtube.com/watch?v=aAmP-WcI6dg}
///
12 13 14 15 16 17 18 19
/// 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.
  ///
20
  /// The [size] defaults to the value given by the current [IconTheme].
21 22 23
  ///
  /// The [textColor], [style], [duration], and [curve] arguments must not be
  /// null.
24
  const FlutterLogo({
25
    super.key,
26
    this.size,
27
    this.textColor = const Color(0xFF757575),
28 29 30
    this.style = FlutterLogoStyle.markOnly,
    this.duration = const Duration(milliseconds: 750),
    this.curve = Curves.fastOutSlowIn,
31 32 33
  }) : assert(textColor != null),
       assert(style != null),
       assert(duration != null),
34
       assert(curve != null);
35 36 37 38 39 40 41 42

  /// 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.
43
  final double? size;
44

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

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

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

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

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