Skip to main content

prefer-define-hero-tag

added in: 1.6.0
🛠
Pro+

Warns when a Widget has an unset heroTag.

When heroTag is not set, the default value is used. Having two or more widgets with the same heroTag will result in an error.

Example

❌ Bad:

// LINT: This widget is missing the 'heroTag' argument. Try adding it.
FloatingActionButton(
onPressed: () => context.read<CounterCubit>().increment(),
child: const Icon(Icons.add),
);

✅ Good:

FloatingActionButton(
onPressed: () => context.read<CounterCubit>().increment(),
child: const Icon(Icons.add),
heroTag: 'increment_heroTag',
);