"Fossies" - the Fresh Open Source Software Archive

Member "flutter-1.22.4/packages/flutter/lib/src/material/data_table_theme.dart" (13 Nov 2020, 8958 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 'material_state.dart';
   13 import 'theme.dart';
   14 
   15 /// Defines default property values for descendant [DataTable]
   16 /// widgets.
   17 ///
   18 /// Descendant widgets obtain the current [DataTableThemeData] object
   19 /// using `DataTableTheme.of(context)`. Instances of
   20 /// [DataTableThemeData] can be customized with
   21 /// [DataTableThemeData.copyWith].
   22 ///
   23 /// Typically a [DataTableThemeData] is specified as part of the
   24 /// overall [Theme] with [ThemeData.dataTableTheme].
   25 ///
   26 /// All [DataTableThemeData] properties are `null` by default. When
   27 /// null, the [DataTable] will use the values from [ThemeData] if they exist,
   28 /// otherwise it will provide its own defaults based on the overall [Theme]'s
   29 /// textTheme and colorScheme. See the individual [DataTable] properties for
   30 /// details.
   31 ///
   32 /// See also:
   33 ///
   34 ///  * [ThemeData], which describes the overall theme information for the
   35 ///    application.
   36 @immutable
   37 class DataTableThemeData with Diagnosticable {
   38   /// Creates a theme that can be used for [ThemeData.dataTableTheme].
   39   const DataTableThemeData({
   40     this.dataRowColor,
   41     this.dataRowHeight,
   42     this.dataTextStyle,
   43     this.headingRowColor,
   44     this.headingRowHeight,
   45     this.headingTextStyle,
   46     this.horizontalMargin,
   47     this.columnSpacing,
   48     this.dividerThickness,
   49   });
   50 
   51   /// {@macro flutter.material.dataTable.dataRowColor}
   52   /// {@macro flutter.material.dataTable.dataRowColorCode}
   53   final MaterialStateProperty<Color> dataRowColor;
   54 
   55   /// {@macro flutter.material.dataTable.dataRowHeight}
   56   final double dataRowHeight;
   57 
   58   /// {@macro flutter.material.dataTable.dataTextStyle}
   59   final TextStyle dataTextStyle;
   60 
   61   /// {@macro flutter.material.dataTable.headingRowColor}
   62   final MaterialStateProperty<Color> headingRowColor;
   63 
   64   /// {@macro flutter.material.dataTable.headingRowHeight}
   65   final double headingRowHeight;
   66 
   67   /// {@macro flutter.material.dataTable.headingTextStyle}
   68   final TextStyle headingTextStyle;
   69 
   70   /// {@macro flutter.material.dataTable.horizontalMargin}
   71   final double horizontalMargin;
   72 
   73   /// {@macro flutter.material.dataTable.columnSpacing}
   74   final double columnSpacing;
   75 
   76   /// {@macro flutter.material.dataTable.dividerThickness}
   77   final double dividerThickness;
   78 
   79   /// Creates a copy of this object but with the given fields replaced with the
   80   /// new values.
   81   DataTableThemeData copyWith({
   82     MaterialStateProperty<Color> dataRowColor,
   83     double dataRowHeight,
   84     TextStyle dataTextStyle,
   85     MaterialStateProperty<Color> headingRowColor,
   86     double headingRowHeight,
   87     TextStyle headingTextStyle,
   88     double horizontalMargin,
   89     double columnSpacing,
   90     double dividerThickness,
   91   }) {
   92     return DataTableThemeData(
   93       dataRowColor: dataRowColor ?? this.dataRowColor,
   94       dataRowHeight: dataRowHeight ?? this.dataRowHeight,
   95       dataTextStyle: dataTextStyle ?? this.dataTextStyle,
   96       headingRowColor: headingRowColor ?? this.headingRowColor,
   97       headingRowHeight: headingRowHeight ?? this.headingRowHeight,
   98       headingTextStyle: headingTextStyle ?? this.headingTextStyle,
   99       horizontalMargin: horizontalMargin ?? this.horizontalMargin,
  100       columnSpacing: columnSpacing ?? this.columnSpacing,
  101       dividerThickness: dividerThickness ?? this.dividerThickness,
  102     );
  103   }
  104 
  105   /// Linearly interpolate between two [DataTableThemeData]s.
  106   ///
  107   /// The argument `t` must not be null.
  108   ///
  109   /// {@macro dart.ui.shadow.lerp}
  110   static DataTableThemeData lerp(DataTableThemeData a, DataTableThemeData b, double t) {
  111     assert(t != null);
  112     return DataTableThemeData(
  113       dataRowColor: _lerpProperties(a.dataRowColor, b.dataRowColor, t, Color.lerp),
  114       dataRowHeight: lerpDouble(a.dataRowHeight, b.dataRowHeight, t),
  115       dataTextStyle: TextStyle.lerp(a.dataTextStyle, b.dataTextStyle, t),
  116       headingRowColor: _lerpProperties(a.headingRowColor, b.headingRowColor, t, Color.lerp),
  117       headingRowHeight: lerpDouble(a.headingRowHeight, b.headingRowHeight, t),
  118       headingTextStyle: TextStyle.lerp(a.headingTextStyle, b.headingTextStyle, t),
  119       horizontalMargin: lerpDouble(a.horizontalMargin, b.horizontalMargin, t),
  120       columnSpacing: lerpDouble(a.columnSpacing, b.columnSpacing, t),
  121       dividerThickness: lerpDouble(a.dividerThickness, b.dividerThickness, t)
  122     );
  123   }
  124 
  125   @override
  126   int get hashCode {
  127     return hashValues(
  128       dataRowColor,
  129       dataRowHeight,
  130       dataTextStyle,
  131       headingRowColor,
  132       headingRowHeight,
  133       headingTextStyle,
  134       horizontalMargin,
  135       columnSpacing,
  136       dividerThickness,
  137     );
  138   }
  139 
  140   @override
  141   bool operator ==(Object other) {
  142     if (identical(this, other))
  143       return true;
  144     if (other.runtimeType != runtimeType)
  145       return false;
  146     return other is DataTableThemeData
  147       && other.dataRowColor == dataRowColor
  148       && other.dataRowHeight == dataRowHeight
  149       && other.dataTextStyle == dataTextStyle
  150       && other.headingRowColor == headingRowColor
  151       && other.headingRowHeight == headingRowHeight
  152       && other.headingTextStyle == headingTextStyle
  153       && other.horizontalMargin == horizontalMargin
  154       && other.columnSpacing == columnSpacing
  155       && other.dividerThickness == dividerThickness;
  156   }
  157 
  158   @override
  159   void debugFillProperties(DiagnosticPropertiesBuilder properties) {
  160     super.debugFillProperties(properties);
  161     properties.add(DiagnosticsProperty<MaterialStateProperty<Color>>('dataRowColor', dataRowColor, defaultValue: null));
  162     properties.add(DoubleProperty('dataRowHeight', dataRowHeight, defaultValue: null));
  163     properties.add(DiagnosticsProperty<TextStyle>('dataTextStyle', dataTextStyle, defaultValue: null));
  164     properties.add(DiagnosticsProperty<MaterialStateProperty<Color>>('headingRowColor', headingRowColor, defaultValue: null));
  165     properties.add(DoubleProperty('headingRowHeight', headingRowHeight, defaultValue: null));
  166     properties.add(DiagnosticsProperty<TextStyle>('headingTextStyle', headingTextStyle, defaultValue: null));
  167     properties.add(DoubleProperty('horizontalMargin', horizontalMargin, defaultValue: null));
  168     properties.add(DoubleProperty('columnSpacing', columnSpacing, defaultValue: null));
  169     properties.add(DoubleProperty('dividerThickness', dividerThickness, defaultValue: null));
  170   }
  171 
  172   static MaterialStateProperty<T> _lerpProperties<T>(MaterialStateProperty<T> a, MaterialStateProperty<T> b, double t, T Function(T, T, double) lerpFunction ) {
  173     // Avoid creating a _LerpProperties object for a common case.
  174     if (a == null && b == null)
  175       return null;
  176     return _LerpProperties<T>(a, b, t, lerpFunction);
  177   }
  178 }
  179 
  180 class _LerpProperties<T> implements MaterialStateProperty<T> {
  181   const _LerpProperties(this.a, this.b, this.t, this.lerpFunction);
  182 
  183   final MaterialStateProperty<T> a;
  184   final MaterialStateProperty<T> b;
  185   final double t;
  186   final T Function(T, T, double) lerpFunction;
  187 
  188   @override
  189   T resolve(Set<MaterialState> states) {
  190     final T resolvedA = a?.resolve(states);
  191     final T resolvedB = b?.resolve(states);
  192     return lerpFunction(resolvedA, resolvedB, t);
  193   }
  194 }
  195 
  196 /// Applies a data table theme to descendant [DataTable] widgets.
  197 ///
  198 /// Descendant widgets obtain the current theme's [DataTableTheme] object using
  199 /// [DataTableTheme.of]. When a widget uses [DataTableTheme.of], it is
  200 /// automatically rebuilt if the theme later changes.
  201 ///
  202 /// A data table theme can be specified as part of the overall Material
  203 /// theme using [ThemeData.dataTableTheme].
  204 ///
  205 /// See also:
  206 ///
  207 ///  * [DataTableThemeData], which describes the actual configuration
  208 ///    of a data table theme.
  209 class DataTableTheme extends InheritedWidget {
  210   /// Constructs a data table theme that configures all descendant
  211   /// [DataTable] widgets.
  212   ///
  213   /// The [data] must not be null.
  214   const DataTableTheme({
  215     Key key,
  216     @required this.data,
  217     Widget child,
  218   }) : assert(data != null), super(key: key, child: child);
  219 
  220   /// The properties used for all descendant [DataTable] widgets.
  221   final DataTableThemeData data;
  222 
  223   /// Returns the configuration [data] from the closest
  224   /// [DataTableTheme] ancestor. If there is no ancestor, it returns
  225   /// [ThemeData.dataTableTheme]. Applications can assume that the
  226   /// returned value will not be null.
  227   ///
  228   /// Typical usage is as follows:
  229   ///
  230   /// ```dart
  231   /// DataTableThemeData theme = DataTableTheme.of(context);
  232   /// ```
  233   static DataTableThemeData of(BuildContext context) {
  234     final DataTableTheme dataTableTheme = context.dependOnInheritedWidgetOfExactType<DataTableTheme>();
  235     return dataTableTheme?.data ?? Theme.of(context).dataTableTheme;
  236   }
  237 
  238   @override
  239   bool updateShouldNotify(DataTableTheme oldWidget) => data != oldWidget.data;
  240 }