ChipThemeData class

Holds the color, shape, and text styles for a Material Design chip theme.

Use this class to configure a ChipTheme widget, or to set the ThemeData.chipTheme for a Theme widget.

To obtain the current ambient chip theme, use ChipTheme.of.

The parts of a chip are:

  • The "avatar", which is a widget that appears at the beginning of the chip. This is typically a CircleAvatar widget.
  • The "label", which is the widget displayed in the center of the chip. Typically this is a Text widget.
  • The "delete icon", which is a widget that appears at the end of the chip.
  • The chip is disabled when it is not accepting user input. Only some chips have a disabled state: ActionChip, ChoiceChip, FilterChip, and InputChip.

The simplest way to create a ChipThemeData is to use copyWith on the one you get from ChipTheme.of, or create an entirely new one with ChipThemeData.fromDefaults.

link
class CarColor extends StatefulWidget {
  const CarColor({super.key});

  @override
  State createState() => _CarColorState();
}

class _CarColorState extends State<CarColor> {
  Color _color = Colors.red;

  @override
  Widget build(BuildContext context) {
    return ChipTheme(
      data: ChipTheme.of(context).copyWith(backgroundColor: Colors.lightBlue),
      child: ChoiceChip(
        label: const Text('Light Blue'),
        onSelected: (bool value) {
          setState(() {
            _color = value ? Colors.lightBlue : Colors.red;
          });
        },
        selected: _color == Colors.lightBlue,
      ),
    );
  }
}

See also:

  • Chip, a chip that displays information and can be deleted.
  • InputChip, a chip that represents a complex piece of information, such as an entity (person, place, or thing) or conversational text, in a compact form.
  • ChoiceChip, allows a single selection from a set of options. Choice chips contain related descriptive text or categories.
  • FilterChip, uses tags or descriptive words as a way to filter content.
  • ActionChip, represents an action related to primary content.
  • CircleAvatar, which shows images or initials of entities.
  • Wrap, A widget that displays its children in multiple horizontal or vertical runs.
  • ChipTheme widget, which can override the chip theme of its children.
  • Theme widget, which performs a similar function to ChipTheme, but for overall themes.
  • ThemeData, which has a default ChipThemeData.
Mixed in types
Annotations

Constructors

ChipThemeData({MaterialStateProperty<Color?>? color, Color? backgroundColor, Color? deleteIconColor, Color? disabledColor, Color? selectedColor, Color? secondarySelectedColor, Color? shadowColor, Color? surfaceTintColor, Color? selectedShadowColor, bool? showCheckmark, Color? checkmarkColor, EdgeInsetsGeometry? labelPadding, EdgeInsetsGeometry? padding, BorderSide? side, OutlinedBorder? shape, TextStyle? labelStyle, TextStyle? secondaryLabelStyle, Brightness? brightness, double? elevation, double? pressElevation, IconThemeData? iconTheme})
Create a ChipThemeData given a set of exact values. All the values must be specified except for shadowColor, selectedShadowColor, elevation, and pressElevation, which may be null.
const
ChipThemeData.fromDefaults({Brightness? brightness, Color? primaryColor, required Color secondaryColor, required TextStyle labelStyle})
Generates a ChipThemeData from a brightness, a primary color, and a text style.
factory

Properties

backgroundColor Color?
Overrides the default for ChipAttributes.backgroundColor which is used for unselected, enabled chip backgrounds.
final
brightness Brightness?
Overrides the default value for all chips which affects various base material color choices in the chip rendering.
final
checkmarkColor Color?
Overrides the default for CheckmarkableChipAttributes.checkmarkColor.
final
color MaterialStateProperty<Color?>?
Overrides the default for ChipAttributes.color.
final
deleteIconColor Color?
Overrides the default for DeletableChipAttributes.deleteIconColor.
final
disabledColor Color?
Overrides the default for DisabledChipAttributes.disabledColor, the background color which indicates that the chip is not enabled.
final
elevation double?
Overrides the default for ChipAttributes.elevation, the elevation of the chip's Material.
final
hashCode int
The hash code for this object.
no setteroverride
iconTheme IconThemeData?
Overrides the default for ChipAttributes.iconTheme, the theme used for all icons in the chip.
final
labelPadding EdgeInsetsGeometry?
Overrides the default for ChipAttributes.labelPadding, the padding around the chip's label widget.
final
labelStyle TextStyle?
Overrides the default for ChipAttributes.labelStyle, the style of the DefaultTextStyle that contains the chip's label.
final
padding EdgeInsetsGeometry?
Overrides the default for ChipAttributes.padding, the padding between the contents of the chip and the outside shape.
final
pressElevation double?
Overrides the default for TappableChipAttributes.pressElevation, the elevation of the chip's Material during a "press" or tap down.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
secondaryLabelStyle TextStyle?
Overrides the default for ChoiceChip.labelStyle, the style of the DefaultTextStyle that contains the chip's label.
final
secondarySelectedColor Color?
Overrides the default for ChoiceChip.selectedColor, the background color that indicates that the chip is selected.
final
selectedColor Color?
Overrides the default for SelectableChipAttributes.selectedColor, the background color that indicates that the chip is selected.
final
selectedShadowColor Color?
Overrides the default for SelectableChipAttributes.selectedShadowColor, the Color of the chip's shadow when its elevation is greater than 0 and the chip is selected.
final
shadowColor Color?
Overrides the default for ChipAttributes.shadowColor, the Color of the chip's shadow when its elevation is greater than 0.
final
shape OutlinedBorder?
Overrides the default for ChipAttributes.shape, the shape of border to draw around the chip.
final
showCheckmark bool?
Overrides the default for CheckmarkableChipAttributes.showCheckmark, which indicates if a check mark should be shown.
final
side BorderSide?
Overrides the default for ChipAttributes.side, the color and weight of the chip's outline.
final
surfaceTintColor Color?
Overrides the default for ChipAttributes.surfaceTintColor, the Color of the chip's surface tint overlay when its elevation is greater than 0.
final

Methods

copyWith({MaterialStateProperty<Color?>? color, Color? backgroundColor, Color? deleteIconColor, Color? disabledColor, Color? selectedColor, Color? secondarySelectedColor, Color? shadowColor, Color? surfaceTintColor, Color? selectedShadowColor, bool? showCheckmark, Color? checkmarkColor, EdgeInsetsGeometry? labelPadding, EdgeInsetsGeometry? padding, BorderSide? side, OutlinedBorder? shape, TextStyle? labelStyle, TextStyle? secondaryLabelStyle, Brightness? brightness, double? elevation, double? pressElevation, IconThemeData? iconTheme}) ChipThemeData
Creates a copy of this object but with the given fields replaced with the new values.
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringShort() String
A brief description of this object, usually just the runtimeType and the hashCode.
inherited

Operators

operator ==(Object other) bool
The equality operator.
override

Static Methods

lerp(ChipThemeData? a, ChipThemeData? b, double t) ChipThemeData?
Linearly interpolate between two chip themes.