prefer-define-hero-tag

Path
lint/correctness/prefer-define-hero-tag
Default
Off, opt in
Origin
Falcon
Domain
flutter
Rule
347 of 512
flutter

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

example.dartdart
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();
}
Provide an explicit `heroTag` for this floating action button.
5void actions() {
6 FloatingActionButton();
Provide an explicit `heroTag` for this floating action button.
6 FloatingActionButton();
7 new FloatingActionButton.small();
Provide an explicit `heroTag` for this floating action button.
7 new FloatingActionButton.small();
8 const f.FloatingActionButton.large();
Provide an explicit `heroTag` for this floating action button.
8 const f.FloatingActionButton.large();
9 FloatingActionButton.extended(label: Text('Add'));
Provide an explicit `heroTag` for this floating action button.
9 FloatingActionButton.extended(label: Text('Add'));
10 Action();

Valid

example.dartdart
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.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "correctness": {
        "prefer-define-hero-tag": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/correctness/prefer-define-hero-tag: <reason>