Skip to content

Commit 90504b1

Browse files
Adjust the IconButton constraint to match its size (flutter#6226)
Fixes flutter#5763
1 parent 3c40c85 commit 90504b1

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'dart:math' as math;
6+
57
import 'package:flutter/widgets.dart';
68
import 'package:meta/meta.dart';
79

@@ -126,7 +128,7 @@ class IconButton extends StatelessWidget {
126128
maxHeight: size,
127129
child: new ConstrainedBox(
128130
constraints: new BoxConstraints.loose(
129-
const Size.square(InkSplash.defaultRadius * 2.0)
131+
new Size.square(math.max(size, InkSplash.defaultRadius * 2.0))
130132
),
131133
child: new Align(
132134
alignment: alignment,
@@ -150,7 +152,8 @@ class IconButton extends StatelessWidget {
150152
}
151153
return new InkResponse(
152154
onTap: onPressed,
153-
child: result
155+
child: result,
156+
radius: math.max(size, InkSplash.defaultRadius),
154157
);
155158
}
156159

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ class InkResponse extends StatefulWidget {
3636
this.onLongPress,
3737
this.onHighlightChanged,
3838
this.containedInkWell: false,
39-
this.highlightShape: BoxShape.circle
39+
this.highlightShape: BoxShape.circle,
40+
this.radius,
4041
}) : super(key: key);
4142

4243
/// The widget below this widget in the tree.
@@ -64,6 +65,9 @@ class InkResponse extends StatefulWidget {
6465
/// The shape (e.g., circle, rectangle) to use for the highlight drawn around this part of the material.
6566
final BoxShape highlightShape;
6667

68+
/// The radius of the ink splash.
69+
final double radius;
70+
6771
/// The rectangle to use for the highlight effect and for clipping
6872
/// the splash effects if [containedInkWell] is true.
6973
///
@@ -138,6 +142,7 @@ class _InkResponseState<T extends InkResponse> extends State<T> {
138142
color: Theme.of(context).splashColor,
139143
containedInkWell: config.containedInkWell,
140144
rectCallback: config.containedInkWell ? rectCallback : null,
145+
radius: config.radius,
141146
onRemoved: () {
142147
if (_splashes != null) {
143148
assert(_splashes.contains(splash));

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ abstract class MaterialInkController {
121121
Color color,
122122
bool containedInkWell: false,
123123
RectCallback rectCallback,
124-
VoidCallback onRemoved
124+
VoidCallback onRemoved,
125+
double radius,
125126
});
126127

127128
/// Begin a highlight animation. If a rectCallback is given, then it
@@ -321,9 +322,9 @@ class _RenderInkFeatures extends RenderProxyBox implements MaterialInkController
321322
Color color,
322323
bool containedInkWell: false,
323324
RectCallback rectCallback,
324-
VoidCallback onRemoved
325+
VoidCallback onRemoved,
326+
double radius,
325327
}) {
326-
double radius;
327328
RectCallback clipCallback;
328329
if (containedInkWell) {
329330
Size size;
@@ -334,10 +335,10 @@ class _RenderInkFeatures extends RenderProxyBox implements MaterialInkController
334335
size = referenceBox.size;
335336
clipCallback = () => Point.origin & referenceBox.size;
336337
}
337-
radius = _getSplashTargetSize(size, position);
338+
radius ??= _getSplashTargetSize(size, position);
338339
} else {
339340
assert(rectCallback == null);
340-
radius = InkSplash.defaultRadius;
341+
radius ??= InkSplash.defaultRadius;
341342
}
342343
_InkSplash splash = new _InkSplash(
343344
controller: this,

packages/flutter/test/material/icon_button_test.dart

+7-4
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,24 @@ import 'package:flutter_test/flutter_test.dart';
77

88
void main() {
99
testWidgets('IconButton test constrained size', (WidgetTester tester) async {
10+
const double kIconSize = 80.0;
11+
1012
await tester.pumpWidget(
1113
new Material(
1214
child: new Center(
1315
child: new IconButton(
1416
padding: EdgeInsets.zero,
1517
onPressed: () {},
16-
icon: new Icon(Icons.ac_unit)
18+
icon: new Icon(Icons.ac_unit),
19+
size: kIconSize,
1720
)
1821
)
1922
)
2023
);
2124

2225
RenderBox box = tester.renderObject(find.byType(IconButton));
23-
expect(box.size.width, equals(InkSplash.defaultRadius * 2.0));
24-
expect(box.size.height, equals(InkSplash.defaultRadius * 2.0));
26+
expect(box.size.width, equals(kIconSize));
27+
expect(box.size.height, equals(kIconSize));
2528
});
2629

2730
testWidgets('IconButton AppBar size', (WidgetTester tester) async {
@@ -32,7 +35,7 @@ void main() {
3235
new IconButton(
3336
padding: EdgeInsets.zero,
3437
onPressed: () {},
35-
icon: new Icon(Icons.ac_unit)
38+
icon: new Icon(Icons.ac_unit),
3639
)
3740
]
3841
)

0 commit comments

Comments
 (0)