diff --git a/packages/flutter/lib/src/material/icon_button.dart b/packages/flutter/lib/src/material/icon_button.dart index ee935a975f..05b05fec4b 100644 --- a/packages/flutter/lib/src/material/icon_button.dart +++ b/packages/flutter/lib/src/material/icon_button.dart @@ -142,6 +142,7 @@ class IconButton extends StatelessWidget { this.visualDensity, this.padding = const EdgeInsets.all(8.0), this.alignment = Alignment.center, + this.splashRadius, @required this.icon, this.color, this.focusColor, @@ -158,6 +159,7 @@ class IconButton extends StatelessWidget { }) : assert(iconSize != null), assert(padding != null), assert(alignment != null), + assert(splashRadius == null || splashRadius > 0), assert(autofocus != null), assert(icon != null), super(key: key); @@ -202,6 +204,11 @@ class IconButton extends StatelessWidget { /// relative to text direction. 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.size] and [Icon.color] of the icon is configured automatically @@ -369,7 +376,7 @@ class IconButton extends StatelessWidget { hoverColor: hoverColor ?? Theme.of(context).hoverColor, highlightColor: highlightColor ?? Theme.of(context).highlightColor, splashColor: splashColor ?? Theme.of(context).splashColor, - radius: math.max( + radius: splashRadius ?? math.max( Material.defaultSplashRadius, (iconSize + math.min(padding.horizontal, padding.vertical)) * 0.7, // x 0.5 for diameter -> radius and + 40% overflow derived from other Material apps. diff --git a/packages/flutter/test/material/icon_button_test.dart b/packages/flutter/test/material/icon_button_test.dart index 93fd1ef407..fd67d949d3 100644 --- a/packages/flutter/test/material/icon_button_test.dart +++ b/packages/flutter/test/material/icon_button_test.dart @@ -337,6 +337,37 @@ void main() { 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 { final SemanticsTester semantics = SemanticsTester(tester);