Skip to content

Commit f8cd24d

Browse files
authored
Revert "ListTile Material Ripple and Shape Patch (flutter#74373)" (flutter#76134)
This reverts commit 422916d because it causes unexpected changes in the rendering of the background of a ListTile.
1 parent 86a51b1 commit f8cd24d

File tree

8 files changed

+105
-213
lines changed

8 files changed

+105
-213
lines changed

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,13 @@ class Ink extends StatefulWidget {
215215
/// any [padding].
216216
final double? height;
217217

218-
EdgeInsetsGeometry get _paddingIncludingDecoration {
218+
EdgeInsetsGeometry? get _paddingIncludingDecoration {
219219
if (decoration == null || decoration!.padding == null)
220-
return padding ?? EdgeInsets.zero;
221-
final EdgeInsetsGeometry decorationPadding = decoration!.padding!;
220+
return padding;
221+
final EdgeInsetsGeometry? decorationPadding = decoration!.padding;
222222
if (padding == null)
223223
return decorationPadding;
224-
return padding!.add(decorationPadding);
224+
return padding!.add(decorationPadding!);
225225
}
226226

227227
@override
@@ -236,7 +236,6 @@ class Ink extends StatefulWidget {
236236
}
237237

238238
class _InkState extends State<Ink> {
239-
final GlobalKey _boxKey = GlobalKey();
240239
InkDecoration? _ink;
241240

242241
void _handleRemoved() {
@@ -250,31 +249,31 @@ class _InkState extends State<Ink> {
250249
super.deactivate();
251250
}
252251

253-
Widget _build(BuildContext context) {
254-
// By creating the InkDecoration from within a Builder widget, we can
255-
// use the RenderBox of the Padding widget.
252+
Widget _build(BuildContext context, BoxConstraints constraints) {
256253
if (_ink == null) {
257254
_ink = InkDecoration(
258255
decoration: widget.decoration,
259256
configuration: createLocalImageConfiguration(context),
260257
controller: Material.of(context)!,
261-
referenceBox: _boxKey.currentContext!.findRenderObject()! as RenderBox,
258+
referenceBox: context.findRenderObject()! as RenderBox,
262259
onRemoved: _handleRemoved,
263260
);
264261
} else {
265262
_ink!.decoration = widget.decoration;
266263
_ink!.configuration = createLocalImageConfiguration(context);
267264
}
268-
return widget.child ?? Container();
265+
Widget? current = widget.child;
266+
final EdgeInsetsGeometry? effectivePadding = widget._paddingIncludingDecoration;
267+
if (effectivePadding != null)
268+
current = Padding(padding: effectivePadding, child: current);
269+
return current ?? Container();
269270
}
270271

271272
@override
272273
Widget build(BuildContext context) {
273274
assert(debugCheckHasMaterial(context));
274-
Widget result = Padding(
275-
key: _boxKey,
276-
padding: widget._paddingIncludingDecoration,
277-
child: Builder(builder: _build),
275+
Widget result = LayoutBuilder(
276+
builder: _build,
278277
);
279278
if (widget.width != null || widget.height != null) {
280279
result = SizedBox(

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import 'colors.dart';
1111
import 'constants.dart';
1212
import 'debug.dart';
1313
import 'divider.dart';
14-
import 'ink_decoration.dart';
1514
import 'ink_well.dart';
1615
import 'material_state.dart';
1716
import 'theme.dart';
@@ -109,7 +108,7 @@ class ListTileTheme extends InheritedTheme {
109108
final bool dense;
110109

111110
/// {@template flutter.material.ListTileTheme.shape}
112-
/// If specified, [shape] defines the [ListTile]'s shape.
111+
/// If specified, [shape] defines the shape of the [ListTile]'s [InkWell] border.
113112
/// {@endtemplate}
114113
final ShapeBorder? shape;
115114

@@ -838,12 +837,13 @@ class ListTile extends StatelessWidget {
838837
/// widgets within a [Theme].
839838
final VisualDensity? visualDensity;
840839

841-
/// The tile's shape.
840+
/// The shape of the tile's [InkWell].
842841
///
843-
/// Defines the tile's [InkWell.customBorder] and [Ink.decoration] shape.
842+
/// Defines the tile's [InkWell.customBorder].
844843
///
845-
/// If this property is null then [ListTileTheme.shape] is used.
846-
/// If that's null then a rectangular [Border] will be used.
844+
/// If this property is null then [CardTheme.shape] of [ThemeData.cardTheme]
845+
/// is used. If that's null then the shape will be a [RoundedRectangleBorder]
846+
/// with a circular corner radius of 4.0.
847847
final ShapeBorder? shape;
848848

849849
/// The tile's internal padding.
@@ -1185,11 +1185,8 @@ class ListTile extends StatelessWidget {
11851185
child: Semantics(
11861186
selected: selected,
11871187
enabled: enabled,
1188-
child: Ink(
1189-
decoration: ShapeDecoration(
1190-
shape: shape ?? tileTheme.shape ?? const Border(),
1191-
color: _tileBackgroundColor(tileTheme),
1192-
),
1188+
child: ColoredBox(
1189+
color: _tileBackgroundColor(tileTheme),
11931190
child: SafeArea(
11941191
top: false,
11951192
bottom: false,

packages/flutter/lib/src/rendering/sliver_multi_box_adaptor.dart

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -577,13 +577,7 @@ abstract class RenderSliverMultiBoxAdaptor extends RenderSliver
577577

578578
@override
579579
void applyPaintTransform(RenderBox child, Matrix4 transform) {
580-
final SliverMultiBoxAdaptorParentData childParentData = child.parentData! as SliverMultiBoxAdaptorParentData;
581-
if (childParentData.index == null) {
582-
// If the child has no index, such as with the prototype of a
583-
// SliverPrototypeExtentList, then it is not visible, so we give it a
584-
// zero transform to prevent it from painting.
585-
transform.setZero();
586-
} else if (_keepAliveBucket.containsKey(childParentData.index)) {
580+
if (_keepAliveBucket.containsKey(indexOf(child))) {
587581
// It is possible that widgets under kept alive children want to paint
588582
// themselves. For example, the Material widget tries to paint all
589583
// InkFeatures under its subtree as long as they are not disposed. In

packages/flutter/test/material/checkbox_list_tile_test.dart

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ void main() {
134134
)
135135
);
136136

137-
final Rect paddingRect = tester.getRect(find.byType(SafeArea));
137+
final Rect paddingRect = tester.getRect(find.byType(Padding));
138138
final Rect checkboxRect = tester.getRect(find.byType(Checkbox));
139139
final Rect titleRect = tester.getRect(find.text('Title'));
140140

@@ -246,41 +246,43 @@ void main() {
246246
});
247247

248248
testWidgets('CheckboxListTile respects tileColor', (WidgetTester tester) async {
249-
final Color tileColor = Colors.red.shade500;
249+
const Color tileColor = Colors.black;
250250

251251
await tester.pumpWidget(
252252
wrap(
253-
child: Center(
253+
child: const Center(
254254
child: CheckboxListTile(
255255
value: false,
256256
onChanged: null,
257-
title: const Text('Title'),
257+
title: Text('Title'),
258258
tileColor: tileColor,
259259
),
260260
),
261261
),
262262
);
263263

264-
expect(find.byType(Material), paints..path(color: tileColor));
264+
final ColoredBox coloredBox = tester.firstWidget(find.byType(ColoredBox));
265+
expect(coloredBox.color, equals(tileColor));
265266
});
266267

267268
testWidgets('CheckboxListTile respects selectedTileColor', (WidgetTester tester) async {
268-
final Color selectedTileColor = Colors.green.shade500;
269+
const Color selectedTileColor = Colors.black;
269270

270271
await tester.pumpWidget(
271272
wrap(
272-
child: Center(
273+
child: const Center(
273274
child: CheckboxListTile(
274275
value: false,
275276
onChanged: null,
276-
title: const Text('Title'),
277+
title: Text('Title'),
277278
selected: true,
278279
selectedTileColor: selectedTileColor,
279280
),
280281
),
281282
),
282283
);
283284

284-
expect(find.byType(Material), paints..path(color: selectedTileColor));
285+
final ColoredBox coloredBox = tester.firstWidget(find.byType(ColoredBox));
286+
expect(coloredBox.color, equals(selectedTileColor));
285287
});
286288
}

0 commit comments

Comments
 (0)