Skip to content

ActionChip constructor documentation does not match class documentation #137964

@JaspervanRiet

Description

@JaspervanRiet

Is there an existing issue for this?

Use case

I encountered this today while working on our Flutter app, and was confused for a minute at the behaviour I saw (aka not great dev ex). The ActionChip constructor documentation is clear:

  /// ...
  /// The [label], [onPressed], [autofocus], and [clipBehavior] arguments must
  /// not be null. ...

Got it, onPressed must be non-null. Yet the type of onPressed is VoidCallback? and the argument is not required in the constructor, nor is there a constructor assert. When you leave it out, the ActionChip has a very non-intuitive background color, which turns out to be the disabled state. This is actually written about in the class documentation:

/// ... For Material 3, a disabled state is supported for Action
/// chips and is specified with [onPressed] being null. For previous versions
/// of Material Design, it is recommended to remove the Action chip from
/// the interface entirely rather than display a disabled chip.

So it is allowed to be null. That makes the constructor documentation wrong.

Proposal

The intention here seems to me that onPressed should always be set, unless the user desires a disabled state. Thus it would make sense to me to make the onPressed required in the constructor, that makes it intentional. Then, I'd suggest amending the constructor documentation to no longer say that onPressed should be non-null. Happy to make a PR.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listd: api docsIssues with https://api.flutter.dev/f: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions