prefer-define-hero-tag
- Group
- Correctness
- Path
lint/correctness/prefer-define-hero-tag- Default
- Off, opt in
- Origin
- Falcon
- Domain
- flutter
- Rule
- 347 of 512
Require an explicit heroTag on Flutter FloatingActionButton constructors.
The default tag is shared, so multiple buttons can collide during a Hero transition. Set a unique tag or explicitly pass null to disable the transition. Includes unnamed, small, large, and extended constructors; package identities exclude local lookalikes and shadowed names. Matches the DCM rule of this id.
Invalid
import 'package:flutter/material.dart';
import 'package:flutter/material.dart' as f;
typedef Action = FloatingActionButton;
void actions() {
FloatingActionButton();
new FloatingActionButton.small();
const f.FloatingActionButton.large();
FloatingActionButton.extended(label: Text('Add'));
Action();
}void actions() { FloatingActionButton(); FloatingActionButton(); new FloatingActionButton.small(); new FloatingActionButton.small(); const f.FloatingActionButton.large(); const f.FloatingActionButton.large(); FloatingActionButton.extended(label: Text('Add')); FloatingActionButton.extended(label: Text('Add')); Action();Valid
import 'package:flutter/material.dart';
import 'package:flutter/material.dart' as f;
void actions(Object tag) {
FloatingActionButton(heroTag: 'add');
const FloatingActionButton.small(heroTag: 1);
f.FloatingActionButton.large(heroTag: tag);
FloatingActionButton.extended(label: Text('Add'), heroTag: null);
FloatingActionButton(heroTag: (null));
Hero(tag: 'flight');
}
void shadow(dynamic FloatingActionButton) { FloatingActionButton(); }Configure prefer-define-hero-tag
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"correctness": {
"prefer-define-hero-tag": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/correctness/prefer-define-hero-tag: <reason>More correctness rules
- prefer-expect-latertest
Requires expectLater when a canonical expect call receives an unawaited Future.
- prefer-immutable-bloc-eventsrecommendedbloc
Flags Bloc event classes without an explicit @immutable annotation.
- prefer-immutable-bloc-staterecommendedbloc
Flags Bloc state classes without an explicit @immutable annotation.
- prefer-immutable-provider-argumentsriverpod
Requires stable value equality for freshly created Riverpod family keys.
- prefer-read-for-methodsrecommendedprovider
Flags void method actions on a listening Provider lookup during build.
- prefer-ref-read-for-methodsrecommendedriverpod
Flags watching a Riverpod notifier solely to invoke one of its methods.
- prefer-relative-imports
prefer_relative_importsPrefer relative imports for libraries of the same package under
lib/. - prefer-sealed-bloc-eventsrecommendedbloc
Flags Bloc event classes without a sealed or final modifier.