Unverified Commit 4dd3435b authored by guylivneh's avatar guylivneh Committed by GitHub

Add a property to Material icon button to customize the splash radius (#55761)

parent 9d770c10
...@@ -142,6 +142,7 @@ class IconButton extends StatelessWidget { ...@@ -142,6 +142,7 @@ class IconButton extends StatelessWidget {
this.visualDensity, this.visualDensity,
this.padding = const EdgeInsets.all(8.0), this.padding = const EdgeInsets.all(8.0),
this.alignment = Alignment.center, this.alignment = Alignment.center,
this.splashRadius,
@required this.icon, @required this.icon,
this.color, this.color,
this.focusColor, this.focusColor,
...@@ -158,6 +159,7 @@ class IconButton extends StatelessWidget { ...@@ -158,6 +159,7 @@ class IconButton extends StatelessWidget {
}) : assert(iconSize != null), }) : assert(iconSize != null),
assert(padding != null), assert(padding != null),
assert(alignment != null), assert(alignment != null),
assert(splashRadius == null || splashRadius > 0),
assert(autofocus != null), assert(autofocus != null),
assert(icon != null), assert(icon != null),
super(key: key); super(key: key);
...@@ -202,6 +204,11 @@ class IconButton extends StatelessWidget { ...@@ -202,6 +204,11 @@ class IconButton extends StatelessWidget {
/// relative to text direction. /// relative to text direction.
final AlignmentGeometry alignment; final AlignmentGeometry alignment;
/// The splash radius.
///
/// If null, default splash radius of [Material.defaultSplashRadius] is used.
final double splashRadius;
/// The icon to display inside the button. /// The icon to display inside the button.
/// ///
/// The [Icon.size] and [Icon.color] of the icon is configured automatically /// The [Icon.size] and [Icon.color] of the icon is configured automatically
...@@ -369,7 +376,7 @@ class IconButton extends StatelessWidget { ...@@ -369,7 +376,7 @@ class IconButton extends StatelessWidget {
hoverColor: hoverColor ?? Theme.of(context).hoverColor, hoverColor: hoverColor ?? Theme.of(context).hoverColor,
highlightColor: highlightColor ?? Theme.of(context).highlightColor, highlightColor: highlightColor ?? Theme.of(context).highlightColor,
splashColor: splashColor ?? Theme.of(context).splashColor, splashColor: splashColor ?? Theme.of(context).splashColor,
radius: math.max( radius: splashRadius ?? math.max(
Material.defaultSplashRadius, Material.defaultSplashRadius,
(iconSize + math.min(padding.horizontal, padding.vertical)) * 0.7, (iconSize + math.min(padding.horizontal, padding.vertical)) * 0.7,
// x 0.5 for diameter -> radius and + 40% overflow derived from other Material apps. // x 0.5 for diameter -> radius and + 40% overflow derived from other Material apps.
......
...@@ -337,6 +337,37 @@ void main() { ...@@ -337,6 +337,37 @@ void main() {
await gesture.up(); await gesture.up();
}); });
testWidgets('IconButton with explicit splash radius',
(WidgetTester tester) async {
const double splashRadius = 30.0;
await tester.pumpWidget(
MaterialApp(
home: Material(
child: Center(
child: IconButton(
icon: const Icon(Icons.android),
splashRadius: splashRadius,
onPressed: () { /* enable the button */ },
),
),
),
),
);
final Offset center = tester.getCenter(find.byType(IconButton));
final TestGesture gesture = await tester.startGesture(center);
await tester.pump(); // Start gesture.
await tester.pump(const Duration(milliseconds: 1000)); // Wait for splash to be well under way.
expect(
Material.of(tester.element(find.byType(IconButton))),
paints
..circle(radius: splashRadius)
);
await gesture.up();
});
testWidgets('IconButton Semantics (enabled)', (WidgetTester tester) async { testWidgets('IconButton Semantics (enabled)', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester); final SemanticsTester semantics = SemanticsTester(tester);
......
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