Skip to content

Lint for AnimatedBuilder/ValueListenableBuilder's child property #58551

@dnfield

Description

@dnfield

BAD:

return AnimatedBuilder(
  animation: someAnimation,
  builder: _builder,
  // no child
);

Widget _builder(BuildContext context, Widget? child) {
  return SizedBox(
    height: someAnimation.value * someOtherValue,
    child: SomeOtherWidget(), // child does not need the value of the animation
  );
}

GOOD:

return AnimatedBuilder(
  animation: someAnimation,
  builder: _builder,
  child: SomeOtherWidget(),
);

Widget _builder(BuildContext context, Widget? child) {
  return SizedBox(
    height: someAnimation.value * someOtherValue,
    child: child,
  );
}

Similar for ValueListenableBuilder, but that one might be easier because the actual value we're interested in is part of the method signature (so no need to correlate someAnimation as in the AnimatedBuilder).

/cc @Hixie

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packagelinter-lint-proposaltype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions