of method Null safety

ChipThemeData of(
  1. BuildContext context

Returns the data from the closest ChipTheme instance that encloses the given context.

Defaults to the ambient ThemeData.chipTheme if there is no ChipTheme in the given build context.

class Spaceship extends StatelessWidget {
  const Spaceship({Key? key}) : super(key: key);

  Widget build(BuildContext context) {
    return ChipTheme(
      data: ChipTheme.of(context).copyWith(backgroundColor: Colors.red),
      child: ActionChip(
        label: const Text('Launch'),
        onPressed: () { print('We have liftoff!'); },

See also:

  • ChipThemeData, which describes the actual configuration of a chip theme.


static ChipThemeData of(BuildContext context) {
  final ChipTheme? inheritedTheme = context.dependOnInheritedWidgetOfExactType<ChipTheme>();
  return inheritedTheme?.data ?? Theme.of(context).chipTheme;