bottom_app_bar_theme.dart 4.98 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 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:ui' show lerpDouble;

import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';

import 'theme.dart';

/// Defines default property values for descendant [BottomAppBar] widgets.
///
/// Descendant widgets obtain the current [BottomAppBarTheme] object using
/// `BottomAppBarTheme.of(context)`. Instances of [BottomAppBarTheme] can be
/// customized with [BottomAppBarTheme.copyWith].
///
/// Typically a [BottomAppBarTheme] is specified as part of the overall [Theme]
/// with [ThemeData.bottomAppBarTheme].
///
/// All [BottomAppBarTheme] properties are `null` by default. When null, the
/// [BottomAppBar] constructor provides defaults.
///
/// See also:
///
///  * [ThemeData], which describes the overall theme information for the
///    application.
28
@immutable
29
class BottomAppBarTheme with Diagnosticable {
30
  /// Creates a theme that can be used for [ThemeData.bottomAppBarTheme].
31 32 33 34
  const BottomAppBarTheme({
    this.color,
    this.elevation,
    this.shape,
35 36
    this.height,
    this.surfaceTintColor,
37
    this.shadowColor,
38
    this.padding,
39 40
  });

41
  /// Overrides the default value for [BottomAppBar.color].
42 43
  ///
  /// If null, [BottomAppBar] uses [ThemeData.bottomAppBarColor].
44
  final Color? color;
45

46
  /// Overrides the default value for [BottomAppBar.elevation].
47
  final double? elevation;
48

49
  /// Overrides the default value for [BottomAppBar.shape].
50
  final NotchedShape? shape;
51

52
  /// Overrides the default value for [BottomAppBar.height].
53 54
  final double? height;

55
  /// Overrides the default value for [BottomAppBar.surfaceTintColor].
56 57 58 59 60 61
  ///
  /// If null, [BottomAppBar] will not display an overlay color.
  ///
  /// See [Material.surfaceTintColor] for more details.
  final Color? surfaceTintColor;

62 63 64
  /// Overrides the default value for [BottomAppBar.shadowColor].
  final Color? shadowColor;

65 66 67
  /// Overrides the default value for [BottomAppBar.padding].
  final EdgeInsetsGeometry? padding;

68 69 70
  /// Creates a copy of this object but with the given fields replaced with the
  /// new values.
  BottomAppBarTheme copyWith({
71 72 73
    Color? color,
    double? elevation,
    NotchedShape? shape,
74 75
    double? height,
    Color? surfaceTintColor,
76
    Color? shadowColor,
77
    EdgeInsetsGeometry? padding,
78 79 80 81 82
  }) {
    return BottomAppBarTheme(
      color: color ?? this.color,
      elevation: elevation ?? this.elevation,
      shape: shape ?? this.shape,
83 84
      height: height ?? this.height,
      surfaceTintColor: surfaceTintColor ?? this.surfaceTintColor,
85
      shadowColor: shadowColor ?? this.shadowColor,
86
      padding: padding ?? this.padding,
87 88 89 90 91
    );
  }

  /// The [ThemeData.bottomAppBarTheme] property of the ambient [Theme].
  static BottomAppBarTheme of(BuildContext context) {
92
    return Theme.of(context).bottomAppBarTheme;
93 94 95 96 97 98 99
  }

  /// Linearly interpolate between two BAB themes.
  ///
  /// The argument `t` must not be null.
  ///
  /// {@macro dart.ui.shadow.lerp}
100
  static BottomAppBarTheme lerp(BottomAppBarTheme? a, BottomAppBarTheme? b, double t) {
101 102 103
    if (identical(a, b) && a != null) {
      return a;
    }
104 105 106 107
    return BottomAppBarTheme(
      color: Color.lerp(a?.color, b?.color, t),
      elevation: lerpDouble(a?.elevation, b?.elevation, t),
      shape: t < 0.5 ? a?.shape : b?.shape,
108
      height: lerpDouble(a?.height, b?.height, t),
109
      surfaceTintColor: Color.lerp(a?.surfaceTintColor, b?.surfaceTintColor, t),
110
      shadowColor: Color.lerp(a?.shadowColor, b?.shadowColor, t),
111
      padding: EdgeInsetsGeometry.lerp(a?.padding, b?.padding, t),
112 113 114 115
    );
  }

  @override
116 117 118 119
  int get hashCode => Object.hash(
    color,
    elevation,
    shape,
120 121
    height,
    surfaceTintColor,
122
    shadowColor,
123
    padding,
124
  );
125 126

  @override
127
  bool operator ==(Object other) {
128
    if (identical(this, other)) {
129
      return true;
130 131
    }
    if (other.runtimeType != runtimeType) {
132
      return false;
133
    }
134 135 136
    return other is BottomAppBarTheme
        && other.color == color
        && other.elevation == elevation
137 138
        && other.shape == shape
        && other.height == height
139
        && other.surfaceTintColor == surfaceTintColor
140
        && other.shadowColor == shadowColor
141
        && other.padding == padding;
142 143 144 145 146
  }

  @override
  void debugFillProperties(DiagnosticPropertiesBuilder properties) {
    super.debugFillProperties(properties);
147
    properties.add(ColorProperty('color', color, defaultValue: null));
148 149
    properties.add(DiagnosticsProperty<double>('elevation', elevation, defaultValue: null));
    properties.add(DiagnosticsProperty<NotchedShape>('shape', shape, defaultValue: null));
150 151
    properties.add(DiagnosticsProperty<double>('height', height, defaultValue: null));
    properties.add(ColorProperty('surfaceTintColor', surfaceTintColor, defaultValue: null));
152
    properties.add(ColorProperty('shadowColor', shadowColor, defaultValue: null));
153
    properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', padding, defaultValue: null));
154 155
  }
}