Unverified Commit 497b9deb authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Some cleanup of Chips that I found while learning the code. (#16249)

parent a7c10097
...@@ -64,6 +64,10 @@ const Icon _kDefaultDeleteIcon = const Icon(Icons.cancel, size: _kDeleteIconSize ...@@ -64,6 +64,10 @@ const Icon _kDefaultDeleteIcon = const Icon(Icons.cancel, size: _kDeleteIconSize
/// * [ActionChip], represents an action related to primary content. /// * [ActionChip], represents an action related to primary content.
/// * <https://material.google.com/components/chips.html> /// * <https://material.google.com/components/chips.html>
abstract class ChipAttributes { abstract class ChipAttributes {
// This class is intended to be used as an interface, and should not be
// extended directly.
factory ChipAttributes._() => null;
/// The primary content of the chip. /// The primary content of the chip.
/// ///
/// Typically a [Text] widget. /// Typically a [Text] widget.
...@@ -121,6 +125,10 @@ abstract class ChipAttributes { ...@@ -121,6 +125,10 @@ abstract class ChipAttributes {
/// compact form. /// compact form.
/// * <https://material.google.com/components/chips.html> /// * <https://material.google.com/components/chips.html>
abstract class DeletableChipAttributes { abstract class DeletableChipAttributes {
// This class is intended to be used as an interface, and should not be
// extended directly.
factory DeletableChipAttributes._() => null;
/// The icon displayed when [onDeleted] is set. /// The icon displayed when [onDeleted] is set.
/// ///
/// Defaults to an [Icon] widget set to use [Icons.cancel]. /// Defaults to an [Icon] widget set to use [Icons.cancel].
...@@ -212,6 +220,10 @@ abstract class DeletableChipAttributes { ...@@ -212,6 +220,10 @@ abstract class DeletableChipAttributes {
/// * [FilterChip], uses tags or descriptive words as a way to filter content. /// * [FilterChip], uses tags or descriptive words as a way to filter content.
/// * <https://material.google.com/components/chips.html> /// * <https://material.google.com/components/chips.html>
abstract class SelectableChipAttributes { abstract class SelectableChipAttributes {
// This class is intended to be used as an interface, and should not be
// extended directly.
factory SelectableChipAttributes._() => null;
/// Whether or not this chip is selected. /// Whether or not this chip is selected.
/// ///
/// If [onSelected] is not null, this value will be used to determine if the /// If [onSelected] is not null, this value will be used to determine if the
...@@ -290,6 +302,10 @@ abstract class SelectableChipAttributes { ...@@ -290,6 +302,10 @@ abstract class SelectableChipAttributes {
/// * [FilterChip], uses tags or descriptive words as a way to filter content. /// * [FilterChip], uses tags or descriptive words as a way to filter content.
/// * <https://material.google.com/components/chips.html> /// * <https://material.google.com/components/chips.html>
abstract class DisabledChipAttributes { abstract class DisabledChipAttributes {
// This class is intended to be used as an interface, and should not be
// extended directly.
factory DisabledChipAttributes._() => null;
/// Whether or not this chip is enabled for input. /// Whether or not this chip is enabled for input.
/// ///
/// If this is true, but all of the user action callbacks are null (i.e. /// If this is true, but all of the user action callbacks are null (i.e.
...@@ -333,6 +349,10 @@ abstract class DisabledChipAttributes { ...@@ -333,6 +349,10 @@ abstract class DisabledChipAttributes {
/// * [ActionChip], represents an action related to primary content. /// * [ActionChip], represents an action related to primary content.
/// * <https://material.google.com/components/chips.html> /// * <https://material.google.com/components/chips.html>
abstract class TappableChipAttributes { abstract class TappableChipAttributes {
// This class is intended to be used as an interface, and should not be
// extended directly.
factory TappableChipAttributes._() => null;
/// Called when the user taps the chip. /// Called when the user taps the chip.
/// ///
/// If [onPressed] is set, then this callback will be called when the user /// If [onPressed] is set, then this callback will be called when the user
...@@ -372,7 +392,7 @@ abstract class TappableChipAttributes { ...@@ -372,7 +392,7 @@ abstract class TappableChipAttributes {
/// button for deleting the chip. /// button for deleting the chip.
/// ///
/// Requires one of its ancestors to be a [Material] widget. The [label], /// Requires one of its ancestors to be a [Material] widget. The [label],
/// [deleteIcon] and [border] arguments must not be null. /// [deleteIcon], and [border] arguments must not be null.
/// ///
/// ## Sample code /// ## Sample code
/// ///
...@@ -402,7 +422,7 @@ abstract class TappableChipAttributes { ...@@ -402,7 +422,7 @@ abstract class TappableChipAttributes {
class Chip extends StatelessWidget implements ChipAttributes, DeletableChipAttributes { class Chip extends StatelessWidget implements ChipAttributes, DeletableChipAttributes {
/// Creates a material design chip. /// Creates a material design chip.
/// ///
/// The [label], [deleteIcon] and [border] arguments must not be null. /// The [label], [deleteIcon], and [border] arguments must not be null.
const Chip({ const Chip({
Key key, Key key,
this.avatar, this.avatar,
...@@ -634,7 +654,7 @@ class InputChip extends StatelessWidget ...@@ -634,7 +654,7 @@ class InputChip extends StatelessWidget
/// related descriptive text or categories. /// related descriptive text or categories.
/// ///
/// Requires one of its ancestors to be a [Material] widget. The [selected], /// Requires one of its ancestors to be a [Material] widget. The [selected],
/// [label] and [border] arguments must not be null. /// [label], and [border] arguments must not be null.
/// ///
/// ## Sample code /// ## Sample code
/// ///
...@@ -684,6 +704,9 @@ class ChoiceChip extends StatelessWidget ...@@ -684,6 +704,9 @@ class ChoiceChip extends StatelessWidget
ChipAttributes, ChipAttributes,
SelectableChipAttributes, SelectableChipAttributes,
DisabledChipAttributes { DisabledChipAttributes {
/// Create a chip that acts like a radio button.
///
/// The [selected], [label], and [border] arguments must not be null.
const ChoiceChip({ const ChoiceChip({
Key key, Key key,
this.avatar, this.avatar,
...@@ -849,6 +872,9 @@ class FilterChip extends StatelessWidget ...@@ -849,6 +872,9 @@ class FilterChip extends StatelessWidget
ChipAttributes, ChipAttributes,
SelectableChipAttributes, SelectableChipAttributes,
DisabledChipAttributes { DisabledChipAttributes {
/// Create a chip that acts like a checkbox.
///
/// The [selected], [label], and [border] arguments must not be null.
const FilterChip({ const FilterChip({
Key key, Key key,
this.avatar, this.avatar,
...@@ -927,17 +953,19 @@ class FilterChip extends StatelessWidget ...@@ -927,17 +953,19 @@ class FilterChip extends StatelessWidget
/// content. Action chips should appear dynamically and contextually in a UI. /// content. Action chips should appear dynamically and contextually in a UI.
/// ///
/// Action chips can be tapped to trigger an action or show progress and /// Action chips can be tapped to trigger an action or show progress and
/// confirmation. /// confirmation. They cannot be disabled; if the action is not applicable, the
/// chip should not be included in the interface. (This contrasts with buttons,
/// where unavailable choices are usually represented as disabled controls.)
/// ///
/// Action chips are displayed after primary content, such as below a card or /// Action chips are displayed after primary content, such as below a card or
/// persistently at the bottom of a screen. /// persistently at the bottom of a screen.
/// ///
/// The material button widgets, [RaisedButton], [FlatButton], [OutlineButton] /// The material button widgets, [RaisedButton], [FlatButton], and
/// are an alternative to action chips, which should appear statically and /// [OutlineButton], are an alternative to action chips, which should appear
/// consistently in a UI. /// statically and consistently in a UI.
/// ///
/// Requires one of its ancestors to be a [Material] widget. The [onPressed], /// Requires one of its ancestors to be a [Material] widget. The [onPressed],
/// [label] and [border] arguments must not be null. /// [label], and [border] arguments must not be null.
/// ///
/// ## Sample code /// ## Sample code
/// ///
...@@ -967,6 +995,9 @@ class FilterChip extends StatelessWidget ...@@ -967,6 +995,9 @@ class FilterChip extends StatelessWidget
/// vertical runs. /// vertical runs.
/// * <https://material.google.com/components/chips.html> /// * <https://material.google.com/components/chips.html>
class ActionChip extends StatelessWidget implements ChipAttributes, TappableChipAttributes { class ActionChip extends StatelessWidget implements ChipAttributes, TappableChipAttributes {
/// Create a chip that acts like a button.
///
/// The [label], [border], and [onPressed] arguments must not be null.
const ActionChip({ const ActionChip({
Key key, Key key,
this.avatar, this.avatar,
...@@ -981,7 +1012,11 @@ class ActionChip extends StatelessWidget implements ChipAttributes, TappableChip ...@@ -981,7 +1012,11 @@ class ActionChip extends StatelessWidget implements ChipAttributes, TappableChip
this.padding, this.padding,
}) : assert(label != null), }) : assert(label != null),
assert(shape != null), assert(shape != null),
assert(onPressed != null), assert(
onPressed != null,
'Rather than disabling an ActionChip by setting onPressed to null, '
'remove it from the interface entirely.',
),
super(key: key); super(key: key);
@override @override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment