"Fossies" - the Fresh Open Source Software Archive

Member "flutter-1.22.4/packages/flutter/lib/src/material/toggle_buttons_theme.dart" (13 Nov 2020, 10527 Bytes) of package /linux/misc/flutter-1.22.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Dart source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // Copyright 2014 The Flutter Authors. All rights reserved.
    2 // Use of this source code is governed by a BSD-style license that can be
    3 // found in the LICENSE file.
    4 
    5 // @dart = 2.8
    6 
    7 import 'dart:ui' show lerpDouble;
    8 
    9 import 'package:flutter/foundation.dart';
   10 import 'package:flutter/rendering.dart';
   11 import 'package:flutter/widgets.dart';
   12 
   13 import 'theme.dart';
   14 
   15 /// Defines the color and border properties of [ToggleButtons] widgets.
   16 ///
   17 /// Used by [ToggleButtonsTheme] to control the color and border properties
   18 /// of toggle buttons in a widget subtree.
   19 ///
   20 /// To obtain the current [ToggleButtonsTheme], use [ToggleButtonsTheme.of].
   21 ///
   22 /// Values specified here are used for [ToggleButtons] properties that are not
   23 /// given an explicit non-null value.
   24 ///
   25 /// See also:
   26 ///
   27 ///  * [ToggleButtonsTheme], which describes the actual configuration of a
   28 ///    toggle buttons theme.
   29 @immutable
   30 class ToggleButtonsThemeData with Diagnosticable {
   31   /// Creates the set of color and border properties used to configure
   32   /// [ToggleButtons].
   33   const ToggleButtonsThemeData({
   34     this.textStyle,
   35     this.constraints,
   36     this.color,
   37     this.selectedColor,
   38     this.disabledColor,
   39     this.fillColor,
   40     this.focusColor,
   41     this.highlightColor,
   42     this.hoverColor,
   43     this.splashColor,
   44     this.borderColor,
   45     this.selectedBorderColor,
   46     this.disabledBorderColor,
   47     this.borderRadius,
   48     this.borderWidth,
   49   });
   50 
   51   /// The default text style for [ToggleButtons.children].
   52   ///
   53   /// [TextStyle.color] will be ignored and substituted by [color],
   54   /// [selectedColor] or [disabledColor] depending on whether the buttons
   55   /// are active, selected, or disabled.
   56   final TextStyle textStyle;
   57 
   58   /// Defines the button's size.
   59   ///
   60   /// Typically used to constrain the button's minimum size.
   61   final BoxConstraints constraints;
   62 
   63   /// The color for descendant [Text] and [Icon] widgets if the toggle button
   64   /// is enabled.
   65   final Color color;
   66 
   67   /// The color for descendant [Text] and [Icon] widgets if the toggle button
   68   /// is selected.
   69   final Color selectedColor;
   70 
   71   /// The color for descendant [Text] and [Icon] widgets if the toggle button
   72   /// is disabled.
   73   final Color disabledColor;
   74 
   75   /// The fill color for selected toggle buttons.
   76   final Color fillColor;
   77 
   78   /// The color to use for filling the button when the button has input focus.
   79   final Color focusColor;
   80 
   81   /// The highlight color for the toggle button's [InkWell].
   82   final Color highlightColor;
   83 
   84   /// The splash color for the toggle button's [InkWell].
   85   final Color splashColor;
   86 
   87   /// The color to use for filling the toggle button when the button has a
   88   /// pointer hovering over it.
   89   final Color hoverColor;
   90 
   91   /// The border color to display when the toggle button is enabled.
   92   final Color borderColor;
   93 
   94   /// The border color to display when the toggle button is selected.
   95   final Color selectedBorderColor;
   96 
   97   /// The border color to display when the toggle button is disabled.
   98   final Color disabledBorderColor;
   99 
  100   /// The width of the border surrounding each toggle button.
  101   ///
  102   /// This applies to both the greater surrounding border, as well as the
  103   /// borders dividing each toggle button.
  104   ///
  105   /// To render a hairline border (one physical pixel), set borderWidth to 0.0.
  106   /// See [BorderSide.width] for more details on hairline borders.
  107   final double borderWidth;
  108 
  109   /// The radii of the border's corners.
  110   final BorderRadius borderRadius;
  111 
  112   /// Creates a copy of this object but with the given fields replaced with the
  113   /// new values.
  114   ToggleButtonsThemeData copyWith({
  115     TextStyle textStyle,
  116     BoxConstraints constraints,
  117     Color color,
  118     Color selectedColor,
  119     Color disabledColor,
  120     Color fillColor,
  121     Color focusColor,
  122     Color highlightColor,
  123     Color hoverColor,
  124     Color splashColor,
  125     Color borderColor,
  126     Color selectedBorderColor,
  127     Color disabledBorderColor,
  128     BorderRadius borderRadius,
  129     double borderWidth,
  130   }) {
  131     return ToggleButtonsThemeData(
  132       textStyle: textStyle ?? this.textStyle,
  133       constraints: constraints ?? this.constraints,
  134       color: color ?? this.color,
  135       selectedColor: selectedColor ?? this.selectedColor,
  136       disabledColor: disabledColor ?? this.disabledColor,
  137       fillColor: fillColor ?? this.fillColor,
  138       focusColor: focusColor ?? this.focusColor,
  139       highlightColor: highlightColor ?? this.highlightColor,
  140       hoverColor: hoverColor ?? this.hoverColor,
  141       splashColor: splashColor ?? this.splashColor,
  142       borderColor: borderColor ?? this.borderColor,
  143       selectedBorderColor: selectedBorderColor ?? this.selectedBorderColor,
  144       disabledBorderColor: disabledBorderColor ?? this.disabledBorderColor,
  145       borderRadius: borderRadius ?? this.borderRadius,
  146       borderWidth: borderWidth ?? this.borderWidth,
  147     );
  148   }
  149 
  150   /// Linearly interpolate between two toggle buttons themes.
  151   static ToggleButtonsThemeData lerp(ToggleButtonsThemeData a, ToggleButtonsThemeData b, double t) {
  152     assert (t != null);
  153     if (a == null && b == null)
  154       return null;
  155     return ToggleButtonsThemeData(
  156       textStyle: TextStyle.lerp(a?.textStyle, b?.textStyle, t),
  157       constraints: BoxConstraints.lerp(a?.constraints, b?.constraints, t),
  158       color: Color.lerp(a?.color, b?.color, t),
  159       selectedColor: Color.lerp(a?.selectedColor, b?.selectedColor, t),
  160       disabledColor: Color.lerp(a?.disabledColor, b?.disabledColor, t),
  161       fillColor: Color.lerp(a?.fillColor, b?.fillColor, t),
  162       focusColor: Color.lerp(a?.focusColor, b?.focusColor, t),
  163       highlightColor: Color.lerp(a?.highlightColor, b?.highlightColor, t),
  164       hoverColor: Color.lerp(a?.hoverColor, b?.hoverColor, t),
  165       splashColor: Color.lerp(a?.splashColor, b?.splashColor, t),
  166       borderColor: Color.lerp(a?.borderColor, b?.borderColor, t),
  167       selectedBorderColor: Color.lerp(a?.selectedBorderColor, b?.selectedBorderColor, t),
  168       disabledBorderColor: Color.lerp(a?.disabledBorderColor, b?.disabledBorderColor, t),
  169       borderRadius: BorderRadius.lerp(a?.borderRadius, b?.borderRadius, t),
  170       borderWidth: lerpDouble(a?.borderWidth, b?.borderWidth, t),
  171     );
  172   }
  173 
  174   @override
  175   int get hashCode {
  176     return hashValues(
  177       textStyle,
  178       constraints,
  179       color,
  180       selectedColor,
  181       disabledColor,
  182       fillColor,
  183       focusColor,
  184       highlightColor,
  185       hoverColor,
  186       splashColor,
  187       borderColor,
  188       selectedBorderColor,
  189       disabledBorderColor,
  190       borderRadius,
  191       borderWidth,
  192     );
  193   }
  194 
  195   @override
  196   bool operator ==(Object other) {
  197     if (identical(this, other))
  198       return true;
  199     if (other.runtimeType != runtimeType)
  200       return false;
  201     return other is ToggleButtonsThemeData
  202         && other.textStyle == textStyle
  203         && other.constraints == constraints
  204         && other.color == color
  205         && other.selectedColor == selectedColor
  206         && other.disabledColor == disabledColor
  207         && other.fillColor == fillColor
  208         && other.focusColor == focusColor
  209         && other.highlightColor == highlightColor
  210         && other.hoverColor == hoverColor
  211         && other.splashColor == splashColor
  212         && other.borderColor == borderColor
  213         && other.selectedBorderColor == selectedBorderColor
  214         && other.disabledBorderColor == disabledBorderColor
  215         && other.borderRadius == borderRadius
  216         && other.borderWidth == borderWidth;
  217   }
  218 
  219   @override
  220   void debugFillProperties(DiagnosticPropertiesBuilder properties) {
  221     super.debugFillProperties(properties);
  222     textStyle?.debugFillProperties(properties, prefix: 'textStyle.');
  223     properties.add(DiagnosticsProperty<BoxConstraints>('constraints', constraints, defaultValue: null));
  224     properties.add(ColorProperty('color', color, defaultValue: null));
  225     properties.add(ColorProperty('selectedColor', selectedColor, defaultValue: null));
  226     properties.add(ColorProperty('disabledColor', disabledColor, defaultValue: null));
  227     properties.add(ColorProperty('fillColor', fillColor, defaultValue: null));
  228     properties.add(ColorProperty('focusColor', focusColor, defaultValue: null));
  229     properties.add(ColorProperty('highlightColor', highlightColor, defaultValue: null));
  230     properties.add(ColorProperty('hoverColor', hoverColor, defaultValue: null));
  231     properties.add(ColorProperty('splashColor', splashColor, defaultValue: null));
  232     properties.add(ColorProperty('borderColor', borderColor, defaultValue: null));
  233     properties.add(ColorProperty('selectedBorderColor', selectedBorderColor, defaultValue: null));
  234     properties.add(ColorProperty('disabledBorderColor', disabledBorderColor, defaultValue: null));
  235     properties.add(DiagnosticsProperty<BorderRadius>('borderRadius', borderRadius, defaultValue: null));
  236     properties.add(DoubleProperty('borderWidth', borderWidth, defaultValue: null));
  237   }
  238 }
  239 
  240 /// An inherited widget that defines color and border parameters for
  241 /// [ToggleButtons] in this widget's subtree.
  242 ///
  243 /// Values specified here are used for [ToggleButtons] properties that are not
  244 /// given an explicit non-null value.
  245 class ToggleButtonsTheme extends InheritedTheme {
  246   /// Creates a toggle buttons theme that controls the color and border
  247   /// parameters for [ToggleButtons].
  248   ///
  249   /// The data argument must not be null.
  250   const ToggleButtonsTheme({
  251     Key key,
  252     @required this.data,
  253     Widget child,
  254   }) : assert(data != null), super(key: key, child: child);
  255 
  256   /// Specifies the color and border values for descendant [ToggleButtons] widgets.
  257   final ToggleButtonsThemeData data;
  258 
  259   /// The closest instance of this class that encloses the given context.
  260   ///
  261   /// If there is no enclosing [ToggleButtonsTheme] widget, then
  262   /// [ThemeData.toggleButtonsTheme] is used.
  263   ///
  264   /// Typical usage is as follows:
  265   ///
  266   /// ```dart
  267   /// ToggleButtonsTheme theme = ToggleButtonsTheme.of(context);
  268   /// ```
  269   static ToggleButtonsThemeData of(BuildContext context) {
  270     final ToggleButtonsTheme toggleButtonsTheme = context.dependOnInheritedWidgetOfExactType<ToggleButtonsTheme>();
  271     return toggleButtonsTheme?.data ?? Theme.of(context).toggleButtonsTheme;
  272   }
  273 
  274   @override
  275   Widget wrap(BuildContext context, Widget child) {
  276     final ToggleButtonsTheme ancestorTheme = context.findAncestorWidgetOfExactType<ToggleButtonsTheme>();
  277     return identical(this, ancestorTheme) ? child : ToggleButtonsTheme(data: data, child: child);
  278   }
  279 
  280   @override
  281   bool updateShouldNotify(ToggleButtonsTheme oldWidget) => data != oldWidget.data;
  282 }