Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save AyushBherwani1998/0dd97981a54f2e55e1ae915194efb2d5 to your computer and use it in GitHub Desktop.

Select an option

Save AyushBherwani1998/0dd97981a54f2e55e1ae915194efb2d5 to your computer and use it in GitHub Desktop.
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
class ListTileThemeData extends Diagnosticable {
const ListTileThemeData({
this.dense,
this.shape,
this.selectedColor,
this.iconColor,
this.textColor,
this.contentPadding,
this.tileColor,
this.selectedTileColor,
});
final bool dense;
final ShapeBorder shape;
final Color selectedColor;
final Color iconColor;
final Color textColor;
final EdgeInsetsGeometry contentPadding;
final Color tileColor;
final Color selectedTileColor;
ListTileThemeData copyWith({
bool dense,
ShapeBorder shape,
Color selectedColor,
Color iconColor,
Color textColor,
EdgeInsetsGeometry contentPadding,
Color tileColor,
Color selectedTileColor,
}) {
return ListTileThemeData(
dense: dense ?? this.dense,
shape: shape ?? this.shape,
selectedColor: selectedColor ?? this.selectedColor,
iconColor: iconColor ?? this.iconColor,
textColor: textColor ?? this.textColor,
contentPadding: contentPadding ?? this.contentPadding,
tileColor: tileColor ?? this.tileColor,
selectedTileColor: selectedTileColor ?? this.selectedColor,
);
}
static ListTileThemeData lerp(ListTileThemeData a, ListTileThemeData b, double t) {
assert(t != null);
if (a == null && b == null)
return null;
return ListTileThemeData(
dense: t < 0.5 ? a?.dense : b?.dense,
shape: ShapeBorder.lerp(a?.shape, b?.shape, t),
selectedTileColor: Color.lerp(a?.selectedColor, b?.selectedColor, t),
iconColor: Color.lerp(a?.iconColor, b?.iconColor, t),
textColor: Color.lerp(a?.textColor, b?.textColor, t),
contentPadding: EdgeInsetsGeometry.lerp(a?.contentPadding, b?.contentPadding, t),
tileColor: Color.lerp(a?.tileColor, b?.tileColor, t),
selectedColor: Color.lerp(a?.selectedColor, b?.selectedColor, t),
);
}
@override
int get hashCode {
return hashValues(
dense,
shape,
selectedColor,
iconColor,
textColor,
contentPadding,
tileColor,
selectedTileColor
);
}
@override
bool operator ==(Object other) {
if (identical(this, other))
return true;
if (other.runtimeType != runtimeType)
return false;
final ListTileThemeData listTileThemeData = other;
return listTileThemeData.dense == dense
&& listTileThemeData.shape == shape
&& listTileThemeData.selectedColor == selectedColor
&& listTileThemeData.iconColor == iconColor
&& listTileThemeData.textColor == textColor
&& listTileThemeData.contentPadding == contentPadding
&& listTileThemeData.tileColor == tileColor
&& listTileThemeData.selectedTileColor == selectedTileColor;
}
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty<bool>('dense', dense, defaultValue: null));
properties.add(DiagnosticsProperty<ShapeBorder>('shape', shape, defaultValue: null));
properties.add(ColorProperty('selectedColor', selectedColor, defaultValue: null));
properties.add(ColorProperty('iconColor', iconColor, defaultValue: null));
properties.add(ColorProperty('textColor', textColor, defaultValue: null));
properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('contentPadding', contentPadding, defaultValue: null));
properties.add(ColorProperty('tileColor', tileColor, defaultValue: null));
properties.add(ColorProperty('selectedTileColor', selectedTileColor, defaultValue: null));
}
}
class ListTileTheme extends InheritedWidget {
ListTileTheme({
Key key,
this.data,
Widget child,
}) : super(key: key, child: child);
final ListTileThemeData data;
static ListTileThemeData of(BuildContext context) {
ListTileTheme listTileTheme = context.dependOnInheritedWidgetOfExactType<ListTileTheme>();
return listTileTheme?.data ?? Theme.of(context).listTileThemeData;
}
@override
bool updateShouldNotify(ListTileTheme oldWidget) {
return oldWidget.data != data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment