Skip to content

Commit ae1f65e

Browse files
authored
Re-organize the Material widget's documentation. (flutter#14303)
This widget evolved over time by multiple people, I'm just trying to explain in a more direct way what the widget is currently doing.
1 parent 6854e81 commit ae1f65e

File tree

1 file changed

+40
-7
lines changed

1 file changed

+40
-7
lines changed

packages/flutter/lib/src/material/material.dart

+40-7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ enum MaterialType {
3535
button,
3636

3737
/// A transparent piece of material that draws ink splashes and highlights.
38+
///
39+
/// While the material metaphor describes child widgets as printed on the
40+
/// material itself and do not hide ink effects, in practice the [Material]
41+
/// widget draws child widgets on top of the ink effects.
42+
/// A [Material] with type transparency can be placed on top of opaque widgets
43+
/// to show ink effects on top of them.
44+
///
45+
/// Prefer using the [Ink] widget for showing ink effects on top of opaque
46+
/// widgets.
3847
transparency
3948
}
4049

@@ -76,6 +85,17 @@ abstract class MaterialInkController {
7685

7786
/// A piece of material.
7887
///
88+
/// The Material widget is responsible for:
89+
///
90+
/// 1. Clipping: Material clips its widget sub-tree to the shape specified by
91+
/// [type] and [borderRadius].
92+
/// 2. Elevation: Material elevates its widget sub-tree on the Z axis by
93+
/// [elevation] pixels, and draws the appropriate shadow.
94+
/// 3. Ink effects: Material shows ink effects implemented by [InkFeature]s
95+
/// like [InkSplash] and [InkHighlight] below its children.
96+
///
97+
/// ## The Material Metaphor
98+
///
7999
/// Material is the central metaphor in material design. Each piece of material
80100
/// exists at a given elevation, which influences how that piece of material
81101
/// visually relates to other pieces of material and how that material casts
@@ -86,9 +106,26 @@ abstract class MaterialInkController {
86106
/// [InkSplash] and [InkHighlight] effects. To trigger a reaction on the
87107
/// material, use a [MaterialInkController] obtained via [Material.of].
88108
///
89-
/// If a material has a non-zero [elevation], then the material will clip its
90-
/// contents because content that is conceptually printing on a separate piece
91-
/// of material cannot be printed beyond the bounds of the material.
109+
/// In general, the features of a [Material] should not change over time (e.g. a
110+
/// [Material] should not change its [color], [shadowColor] or [type]). The one
111+
/// exception is the [elevation], changes to which will be animated.
112+
///
113+
/// ## Shape
114+
///
115+
/// The shape for material is determined by [type] and [borderRadius].
116+
///
117+
/// - If [borderRadius] is non null, the shape is a rounded rectangle, with
118+
/// corners specified by [borderRadius].
119+
/// - If [borderRadius] is null, [type] determines the shape as follows:
120+
/// - [MaterialType.canvas]: the default material shape is a rectangle.
121+
/// - [MaterialType.card]: the default material shape is a rectangle with
122+
/// rounded edges. The edge radii is specified by [kMaterialEdges].
123+
/// - [MaterialType.circle]: the default material shape is a circle.
124+
/// - [MaterialType.button]: the default material shape is a rectangle with
125+
/// rounded edges. The edge radii is specified by [kMaterialEdges].
126+
/// - [MaterialType.transparency]: the default material shape is a rectangle.
127+
///
128+
/// ## Layout change notifications
92129
///
93130
/// If the layout changes (e.g. because there's a list on the material, and it's
94131
/// been scrolled), a [LayoutChangedNotification] must be dispatched at the
@@ -99,10 +136,6 @@ abstract class MaterialInkController {
99136
/// features (e.g., ink splashes and ink highlights) won't move to account for
100137
/// the new layout.
101138
///
102-
/// In general, the features of a [Material] should not change over time (e.g. a
103-
/// [Material] should not change its [color], [shadowColor] or [type]). The one
104-
/// exception is the [elevation], changes to which will be animated.
105-
///
106139
/// See also:
107140
///
108141
/// * [MergeableMaterial], a piece of material that can split and remerge.

0 commit comments

Comments
 (0)