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