Commit 90504b12 authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

Adjust the IconButton constraint to match its size (#6226)

Fixes https://github.com/flutter/flutter/issues/5763
parent 3c40c855
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:math' as math;
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
...@@ -126,7 +128,7 @@ class IconButton extends StatelessWidget { ...@@ -126,7 +128,7 @@ class IconButton extends StatelessWidget {
maxHeight: size, maxHeight: size,
child: new ConstrainedBox( child: new ConstrainedBox(
constraints: new BoxConstraints.loose( constraints: new BoxConstraints.loose(
const Size.square(InkSplash.defaultRadius * 2.0) new Size.square(math.max(size, InkSplash.defaultRadius * 2.0))
), ),
child: new Align( child: new Align(
alignment: alignment, alignment: alignment,
...@@ -150,7 +152,8 @@ class IconButton extends StatelessWidget { ...@@ -150,7 +152,8 @@ class IconButton extends StatelessWidget {
} }
return new InkResponse( return new InkResponse(
onTap: onPressed, onTap: onPressed,
child: result child: result,
radius: math.max(size, InkSplash.defaultRadius),
); );
} }
......
...@@ -36,7 +36,8 @@ class InkResponse extends StatefulWidget { ...@@ -36,7 +36,8 @@ class InkResponse extends StatefulWidget {
this.onLongPress, this.onLongPress,
this.onHighlightChanged, this.onHighlightChanged,
this.containedInkWell: false, this.containedInkWell: false,
this.highlightShape: BoxShape.circle this.highlightShape: BoxShape.circle,
this.radius,
}) : super(key: key); }) : super(key: key);
/// The widget below this widget in the tree. /// The widget below this widget in the tree.
...@@ -64,6 +65,9 @@ class InkResponse extends StatefulWidget { ...@@ -64,6 +65,9 @@ class InkResponse extends StatefulWidget {
/// The shape (e.g., circle, rectangle) to use for the highlight drawn around this part of the material. /// The shape (e.g., circle, rectangle) to use for the highlight drawn around this part of the material.
final BoxShape highlightShape; final BoxShape highlightShape;
/// The radius of the ink splash.
final double radius;
/// The rectangle to use for the highlight effect and for clipping /// The rectangle to use for the highlight effect and for clipping
/// the splash effects if [containedInkWell] is true. /// the splash effects if [containedInkWell] is true.
/// ///
...@@ -138,6 +142,7 @@ class _InkResponseState<T extends InkResponse> extends State<T> { ...@@ -138,6 +142,7 @@ class _InkResponseState<T extends InkResponse> extends State<T> {
color: Theme.of(context).splashColor, color: Theme.of(context).splashColor,
containedInkWell: config.containedInkWell, containedInkWell: config.containedInkWell,
rectCallback: config.containedInkWell ? rectCallback : null, rectCallback: config.containedInkWell ? rectCallback : null,
radius: config.radius,
onRemoved: () { onRemoved: () {
if (_splashes != null) { if (_splashes != null) {
assert(_splashes.contains(splash)); assert(_splashes.contains(splash));
......
...@@ -121,7 +121,8 @@ abstract class MaterialInkController { ...@@ -121,7 +121,8 @@ abstract class MaterialInkController {
Color color, Color color,
bool containedInkWell: false, bool containedInkWell: false,
RectCallback rectCallback, RectCallback rectCallback,
VoidCallback onRemoved VoidCallback onRemoved,
double radius,
}); });
/// Begin a highlight animation. If a rectCallback is given, then it /// Begin a highlight animation. If a rectCallback is given, then it
...@@ -321,9 +322,9 @@ class _RenderInkFeatures extends RenderProxyBox implements MaterialInkController ...@@ -321,9 +322,9 @@ class _RenderInkFeatures extends RenderProxyBox implements MaterialInkController
Color color, Color color,
bool containedInkWell: false, bool containedInkWell: false,
RectCallback rectCallback, RectCallback rectCallback,
VoidCallback onRemoved VoidCallback onRemoved,
double radius,
}) { }) {
double radius;
RectCallback clipCallback; RectCallback clipCallback;
if (containedInkWell) { if (containedInkWell) {
Size size; Size size;
...@@ -334,10 +335,10 @@ class _RenderInkFeatures extends RenderProxyBox implements MaterialInkController ...@@ -334,10 +335,10 @@ class _RenderInkFeatures extends RenderProxyBox implements MaterialInkController
size = referenceBox.size; size = referenceBox.size;
clipCallback = () => Point.origin & referenceBox.size; clipCallback = () => Point.origin & referenceBox.size;
} }
radius = _getSplashTargetSize(size, position); radius ??= _getSplashTargetSize(size, position);
} else { } else {
assert(rectCallback == null); assert(rectCallback == null);
radius = InkSplash.defaultRadius; radius ??= InkSplash.defaultRadius;
} }
_InkSplash splash = new _InkSplash( _InkSplash splash = new _InkSplash(
controller: this, controller: this,
......
...@@ -7,21 +7,24 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -7,21 +7,24 @@ import 'package:flutter_test/flutter_test.dart';
void main() { void main() {
testWidgets('IconButton test constrained size', (WidgetTester tester) async { testWidgets('IconButton test constrained size', (WidgetTester tester) async {
const double kIconSize = 80.0;
await tester.pumpWidget( await tester.pumpWidget(
new Material( new Material(
child: new Center( child: new Center(
child: new IconButton( child: new IconButton(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
onPressed: () {}, onPressed: () {},
icon: new Icon(Icons.ac_unit) icon: new Icon(Icons.ac_unit),
size: kIconSize,
) )
) )
) )
); );
RenderBox box = tester.renderObject(find.byType(IconButton)); RenderBox box = tester.renderObject(find.byType(IconButton));
expect(box.size.width, equals(InkSplash.defaultRadius * 2.0)); expect(box.size.width, equals(kIconSize));
expect(box.size.height, equals(InkSplash.defaultRadius * 2.0)); expect(box.size.height, equals(kIconSize));
}); });
testWidgets('IconButton AppBar size', (WidgetTester tester) async { testWidgets('IconButton AppBar size', (WidgetTester tester) async {
...@@ -32,7 +35,7 @@ void main() { ...@@ -32,7 +35,7 @@ void main() {
new IconButton( new IconButton(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
onPressed: () {}, onPressed: () {},
icon: new Icon(Icons.ac_unit) icon: new Icon(Icons.ac_unit),
) )
] ]
) )
......
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