"Fossies" - the Fresh Open Source Software Archive

Member "flutter-1.22.4/packages/flutter/lib/src/material/divider_theme.dart" (13 Nov 2020, 5750 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/widgets.dart';
   11 
   12 import 'theme.dart';
   13 
   14 /// Defines the visual properties of [Divider], [VerticalDivider], dividers
   15 /// between [ListTile]s, and dividers between rows in [DataTable]s.
   16 ///
   17 /// Descendant widgets obtain the current [DividerThemeData] object using
   18 /// `DividerTheme.of(context)`. Instances of [DividerThemeData]
   19 /// can be customized with [DividerThemeData.copyWith].
   20 ///
   21 /// Typically a [DividerThemeData] is specified as part of the overall
   22 /// [Theme] with [ThemeData.dividerTheme].
   23 ///
   24 /// All [DividerThemeData] properties are `null` by default. When null,
   25 /// the widgets will provide their own defaults.
   26 ///
   27 /// See also:
   28 ///
   29 ///  * [ThemeData], which describes the overall theme information for the
   30 ///    application.
   31 @immutable
   32 class DividerThemeData with Diagnosticable {
   33 
   34   /// Creates a theme that can be used for [DividerTheme] or
   35   /// [ThemeData.dividerTheme].
   36   const DividerThemeData({
   37     this.color,
   38     this.space,
   39     this.thickness,
   40     this.indent,
   41     this.endIndent,
   42   });
   43 
   44   /// The color of [Divider]s and [VerticalDivider]s, also
   45   /// used between [ListTile]s, between rows in [DataTable]s, and so forth.
   46   final Color color;
   47 
   48   /// The [Divider]'s width or the [VerticalDivider]'s height.
   49   ///
   50   /// This represents the amount of horizontal or vertical space the divider
   51   /// takes up.
   52   final double space;
   53 
   54   /// The thickness of the line drawn within the divider.
   55   final double thickness;
   56 
   57   /// The amount of empty space at the leading edge of [Divider] or top edge of
   58   /// [VerticalDivider].
   59   final double indent;
   60 
   61   /// The amount of empty space at the trailing edge of [Divider] or bottom edge
   62   /// of [VerticalDivider].
   63   final double endIndent;
   64 
   65   /// Creates a copy of this object with the given fields replaced with the
   66   /// new values.
   67   DividerThemeData copyWith({
   68     Color color,
   69     double space,
   70     double thickness,
   71     double indent,
   72     double endIndent,
   73   }) {
   74     return DividerThemeData(
   75       color: color ?? this.color,
   76       space: space ?? this.space,
   77       thickness: thickness ?? this.thickness,
   78       indent: indent ?? this.indent,
   79       endIndent: endIndent ?? this.endIndent,
   80     );
   81   }
   82 
   83   /// Linearly interpolate between two Divider themes.
   84   ///
   85   /// The argument `t` must not be null.
   86   ///
   87   /// {@macro dart.ui.shadow.lerp}
   88   static DividerThemeData lerp(DividerThemeData a, DividerThemeData b, double t) {
   89     assert(t != null);
   90     return DividerThemeData(
   91       color: Color.lerp(a?.color, b?.color, t),
   92       space: lerpDouble(a?.space, b?.space, t),
   93       thickness: lerpDouble(a?.thickness, b?.thickness, t),
   94       indent: lerpDouble(a?.indent, b?.indent, t),
   95       endIndent: lerpDouble(a?.endIndent, b?.endIndent, t),
   96     );
   97   }
   98 
   99   @override
  100   int get hashCode {
  101     return hashValues(
  102       color,
  103       space,
  104       thickness,
  105       indent,
  106       endIndent,
  107     );
  108   }
  109 
  110   @override
  111   bool operator ==(Object other) {
  112     if (identical(this, other))
  113       return true;
  114     if (other.runtimeType != runtimeType)
  115       return false;
  116     return other is DividerThemeData
  117         && other.color == color
  118         && other.space == space
  119         && other.thickness == thickness
  120         && other.indent == indent
  121         && other.endIndent == endIndent;
  122   }
  123 
  124   @override
  125   void debugFillProperties(DiagnosticPropertiesBuilder properties) {
  126     super.debugFillProperties(properties);
  127     properties.add(ColorProperty('color', color, defaultValue: null));
  128     properties.add(DoubleProperty('space', space, defaultValue: null));
  129     properties.add(DoubleProperty('thickness', thickness, defaultValue: null));
  130     properties.add(DoubleProperty('indent', indent, defaultValue: null));
  131     properties.add(DoubleProperty('endIndent', endIndent, defaultValue: null));
  132   }
  133 }
  134 
  135 /// An inherited widget that defines the configuration for
  136 /// [Divider]s, [VerticalDivider]s, dividers between [ListTile]s, and dividers
  137 /// between rows in [DataTable]s in this widget's subtree.
  138 class DividerTheme extends InheritedTheme {
  139   /// Creates a divider theme that controls the configurations for
  140   /// [Divider]s, [VerticalDivider]s, dividers between [ListTile]s, and dividers
  141   /// between rows in [DataTable]s in its widget subtree.
  142   const DividerTheme({
  143     Key key,
  144     @required this.data,
  145     Widget child,
  146   }) : assert(data != null),
  147        super(key: key, child: child);
  148 
  149   /// The properties for descendant [Divider]s, [VerticalDivider]s, dividers
  150   /// between [ListTile]s, and dividers between rows in [DataTable]s.
  151   final DividerThemeData data;
  152 
  153   /// The closest instance of this class's [data] value that encloses the given
  154   /// context.
  155   ///
  156   /// If there is no ancestor, it returns [ThemeData.dividerTheme]. Applications
  157   /// can assume that the returned value will not be null.
  158   ///
  159   /// Typical usage is as follows:
  160   ///
  161   /// ```dart
  162   /// DividerThemeData theme = DividerTheme.of(context);
  163   /// ```
  164   static DividerThemeData of(BuildContext context) {
  165     final DividerTheme dividerTheme = context.dependOnInheritedWidgetOfExactType<DividerTheme>();
  166     return dividerTheme?.data ?? Theme.of(context).dividerTheme;
  167   }
  168 
  169   @override
  170   Widget wrap(BuildContext context, Widget child) {
  171     final DividerTheme ancestorTheme = context.findAncestorWidgetOfExactType<DividerTheme>();
  172     return identical(this, ancestorTheme) ? child : DividerTheme(data: data, child: child);
  173   }
  174 
  175   @override
  176   bool updateShouldNotify(DividerTheme oldWidget) => data != oldWidget.data;
  177 }