Unverified Commit f8cd24de authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Revert "ListTile Material Ripple and Shape Patch (#74373)" (#76134)

This reverts commit 422916d2 because it causes unexpected changes in the rendering of the background of a ListTile.
parent 86a51b16
...@@ -215,13 +215,13 @@ class Ink extends StatefulWidget { ...@@ -215,13 +215,13 @@ class Ink extends StatefulWidget {
/// any [padding]. /// any [padding].
final double? height; final double? height;
EdgeInsetsGeometry get _paddingIncludingDecoration { EdgeInsetsGeometry? get _paddingIncludingDecoration {
if (decoration == null || decoration!.padding == null) if (decoration == null || decoration!.padding == null)
return padding ?? EdgeInsets.zero; return padding;
final EdgeInsetsGeometry decorationPadding = decoration!.padding!; final EdgeInsetsGeometry? decorationPadding = decoration!.padding;
if (padding == null) if (padding == null)
return decorationPadding; return decorationPadding;
return padding!.add(decorationPadding); return padding!.add(decorationPadding!);
} }
@override @override
...@@ -236,7 +236,6 @@ class Ink extends StatefulWidget { ...@@ -236,7 +236,6 @@ class Ink extends StatefulWidget {
} }
class _InkState extends State<Ink> { class _InkState extends State<Ink> {
final GlobalKey _boxKey = GlobalKey();
InkDecoration? _ink; InkDecoration? _ink;
void _handleRemoved() { void _handleRemoved() {
...@@ -250,31 +249,31 @@ class _InkState extends State<Ink> { ...@@ -250,31 +249,31 @@ class _InkState extends State<Ink> {
super.deactivate(); super.deactivate();
} }
Widget _build(BuildContext context) { Widget _build(BuildContext context, BoxConstraints constraints) {
// By creating the InkDecoration from within a Builder widget, we can
// use the RenderBox of the Padding widget.
if (_ink == null) { if (_ink == null) {
_ink = InkDecoration( _ink = InkDecoration(
decoration: widget.decoration, decoration: widget.decoration,
configuration: createLocalImageConfiguration(context), configuration: createLocalImageConfiguration(context),
controller: Material.of(context)!, controller: Material.of(context)!,
referenceBox: _boxKey.currentContext!.findRenderObject()! as RenderBox, referenceBox: context.findRenderObject()! as RenderBox,
onRemoved: _handleRemoved, onRemoved: _handleRemoved,
); );
} else { } else {
_ink!.decoration = widget.decoration; _ink!.decoration = widget.decoration;
_ink!.configuration = createLocalImageConfiguration(context); _ink!.configuration = createLocalImageConfiguration(context);
} }
return widget.child ?? Container(); Widget? current = widget.child;
final EdgeInsetsGeometry? effectivePadding = widget._paddingIncludingDecoration;
if (effectivePadding != null)
current = Padding(padding: effectivePadding, child: current);
return current ?? Container();
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
assert(debugCheckHasMaterial(context)); assert(debugCheckHasMaterial(context));
Widget result = Padding( Widget result = LayoutBuilder(
key: _boxKey, builder: _build,
padding: widget._paddingIncludingDecoration,
child: Builder(builder: _build),
); );
if (widget.width != null || widget.height != null) { if (widget.width != null || widget.height != null) {
result = SizedBox( result = SizedBox(
......
...@@ -11,7 +11,6 @@ import 'colors.dart'; ...@@ -11,7 +11,6 @@ import 'colors.dart';
import 'constants.dart'; import 'constants.dart';
import 'debug.dart'; import 'debug.dart';
import 'divider.dart'; import 'divider.dart';
import 'ink_decoration.dart';
import 'ink_well.dart'; import 'ink_well.dart';
import 'material_state.dart'; import 'material_state.dart';
import 'theme.dart'; import 'theme.dart';
...@@ -109,7 +108,7 @@ class ListTileTheme extends InheritedTheme { ...@@ -109,7 +108,7 @@ class ListTileTheme extends InheritedTheme {
final bool dense; final bool dense;
/// {@template flutter.material.ListTileTheme.shape} /// {@template flutter.material.ListTileTheme.shape}
/// If specified, [shape] defines the [ListTile]'s shape. /// If specified, [shape] defines the shape of the [ListTile]'s [InkWell] border.
/// {@endtemplate} /// {@endtemplate}
final ShapeBorder? shape; final ShapeBorder? shape;
...@@ -838,12 +837,13 @@ class ListTile extends StatelessWidget { ...@@ -838,12 +837,13 @@ class ListTile extends StatelessWidget {
/// widgets within a [Theme]. /// widgets within a [Theme].
final VisualDensity? visualDensity; final VisualDensity? visualDensity;
/// The tile's shape. /// The shape of the tile's [InkWell].
/// ///
/// Defines the tile's [InkWell.customBorder] and [Ink.decoration] shape. /// Defines the tile's [InkWell.customBorder].
/// ///
/// If this property is null then [ListTileTheme.shape] is used. /// If this property is null then [CardTheme.shape] of [ThemeData.cardTheme]
/// If that's null then a rectangular [Border] will be used. /// is used. If that's null then the shape will be a [RoundedRectangleBorder]
/// with a circular corner radius of 4.0.
final ShapeBorder? shape; final ShapeBorder? shape;
/// The tile's internal padding. /// The tile's internal padding.
...@@ -1185,11 +1185,8 @@ class ListTile extends StatelessWidget { ...@@ -1185,11 +1185,8 @@ class ListTile extends StatelessWidget {
child: Semantics( child: Semantics(
selected: selected, selected: selected,
enabled: enabled, enabled: enabled,
child: Ink( child: ColoredBox(
decoration: ShapeDecoration( color: _tileBackgroundColor(tileTheme),
shape: shape ?? tileTheme.shape ?? const Border(),
color: _tileBackgroundColor(tileTheme),
),
child: SafeArea( child: SafeArea(
top: false, top: false,
bottom: false, bottom: false,
......
...@@ -577,13 +577,7 @@ abstract class RenderSliverMultiBoxAdaptor extends RenderSliver ...@@ -577,13 +577,7 @@ abstract class RenderSliverMultiBoxAdaptor extends RenderSliver
@override @override
void applyPaintTransform(RenderBox child, Matrix4 transform) { void applyPaintTransform(RenderBox child, Matrix4 transform) {
final SliverMultiBoxAdaptorParentData childParentData = child.parentData! as SliverMultiBoxAdaptorParentData; if (_keepAliveBucket.containsKey(indexOf(child))) {
if (childParentData.index == null) {
// If the child has no index, such as with the prototype of a
// SliverPrototypeExtentList, then it is not visible, so we give it a
// zero transform to prevent it from painting.
transform.setZero();
} else if (_keepAliveBucket.containsKey(childParentData.index)) {
// It is possible that widgets under kept alive children want to paint // It is possible that widgets under kept alive children want to paint
// themselves. For example, the Material widget tries to paint all // themselves. For example, the Material widget tries to paint all
// InkFeatures under its subtree as long as they are not disposed. In // InkFeatures under its subtree as long as they are not disposed. In
......
...@@ -134,7 +134,7 @@ void main() { ...@@ -134,7 +134,7 @@ void main() {
) )
); );
final Rect paddingRect = tester.getRect(find.byType(SafeArea)); final Rect paddingRect = tester.getRect(find.byType(Padding));
final Rect checkboxRect = tester.getRect(find.byType(Checkbox)); final Rect checkboxRect = tester.getRect(find.byType(Checkbox));
final Rect titleRect = tester.getRect(find.text('Title')); final Rect titleRect = tester.getRect(find.text('Title'));
...@@ -246,34 +246,35 @@ void main() { ...@@ -246,34 +246,35 @@ void main() {
}); });
testWidgets('CheckboxListTile respects tileColor', (WidgetTester tester) async { testWidgets('CheckboxListTile respects tileColor', (WidgetTester tester) async {
final Color tileColor = Colors.red.shade500; const Color tileColor = Colors.black;
await tester.pumpWidget( await tester.pumpWidget(
wrap( wrap(
child: Center( child: const Center(
child: CheckboxListTile( child: CheckboxListTile(
value: false, value: false,
onChanged: null, onChanged: null,
title: const Text('Title'), title: Text('Title'),
tileColor: tileColor, tileColor: tileColor,
), ),
), ),
), ),
); );
expect(find.byType(Material), paints..path(color: tileColor)); final ColoredBox coloredBox = tester.firstWidget(find.byType(ColoredBox));
expect(coloredBox.color, equals(tileColor));
}); });
testWidgets('CheckboxListTile respects selectedTileColor', (WidgetTester tester) async { testWidgets('CheckboxListTile respects selectedTileColor', (WidgetTester tester) async {
final Color selectedTileColor = Colors.green.shade500; const Color selectedTileColor = Colors.black;
await tester.pumpWidget( await tester.pumpWidget(
wrap( wrap(
child: Center( child: const Center(
child: CheckboxListTile( child: CheckboxListTile(
value: false, value: false,
onChanged: null, onChanged: null,
title: const Text('Title'), title: Text('Title'),
selected: true, selected: true,
selectedTileColor: selectedTileColor, selectedTileColor: selectedTileColor,
), ),
...@@ -281,6 +282,7 @@ void main() { ...@@ -281,6 +282,7 @@ void main() {
), ),
); );
expect(find.byType(Material), paints..path(color: selectedTileColor)); final ColoredBox coloredBox = tester.firstWidget(find.byType(ColoredBox));
expect(coloredBox.color, equals(selectedTileColor));
}); });
} }
...@@ -8,7 +8,6 @@ import 'package:flutter/rendering.dart'; ...@@ -8,7 +8,6 @@ import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../rendering/mock_canvas.dart';
import '../widgets/semantics_tester.dart'; import '../widgets/semantics_tester.dart';
...@@ -628,7 +627,7 @@ void main() { ...@@ -628,7 +627,7 @@ void main() {
) )
); );
final Rect paddingRect = tester.getRect(find.byType(SafeArea)); final Rect paddingRect = tester.getRect(find.byType(Padding));
final Rect radioRect = tester.getRect(find.byType(radioType)); final Rect radioRect = tester.getRect(find.byType(radioType));
final Rect titleRect = tester.getRect(find.text('Title')); final Rect titleRect = tester.getRect(find.text('Title'));
...@@ -668,36 +667,37 @@ void main() { ...@@ -668,36 +667,37 @@ void main() {
}); });
testWidgets('RadioListTile respects tileColor', (WidgetTester tester) async { testWidgets('RadioListTile respects tileColor', (WidgetTester tester) async {
final Color tileColor = Colors.red.shade500; const Color tileColor = Colors.red;
await tester.pumpWidget( await tester.pumpWidget(
wrap( wrap(
child: Center( child: const Center(
child: RadioListTile<bool>( child: RadioListTile<bool>(
value: false, value: false,
groupValue: true, groupValue: true,
onChanged: null, onChanged: null,
title: const Text('Title'), title: Text('Title'),
tileColor: tileColor, tileColor: tileColor,
), ),
), ),
), ),
); );
expect(find.byType(Material), paints..path(color: tileColor)); final ColoredBox coloredBox = tester.firstWidget(find.byType(ColoredBox));
expect(coloredBox.color, tileColor);
}); });
testWidgets('RadioListTile respects selectedTileColor', (WidgetTester tester) async { testWidgets('RadioListTile respects selectedTileColor', (WidgetTester tester) async {
final Color selectedTileColor = Colors.green.shade500; const Color selectedTileColor = Colors.black;
await tester.pumpWidget( await tester.pumpWidget(
wrap( wrap(
child: Center( child: const Center(
child: RadioListTile<bool>( child: RadioListTile<bool>(
value: false, value: false,
groupValue: true, groupValue: true,
onChanged: null, onChanged: null,
title: const Text('Title'), title: Text('Title'),
selected: true, selected: true,
selectedTileColor: selectedTileColor, selectedTileColor: selectedTileColor,
), ),
...@@ -705,6 +705,7 @@ void main() { ...@@ -705,6 +705,7 @@ void main() {
), ),
); );
expect(find.byType(Material), paints..path(color: selectedTileColor)); final ColoredBox coloredBox = tester.firstWidget(find.byType(ColoredBox));
expect(coloredBox.color, equals(selectedTileColor));
}); });
} }
...@@ -359,34 +359,35 @@ void main() { ...@@ -359,34 +359,35 @@ void main() {
}); });
testWidgets('SwitchListTile respects tileColor', (WidgetTester tester) async { testWidgets('SwitchListTile respects tileColor', (WidgetTester tester) async {
final Color tileColor = Colors.red.shade500; const Color tileColor = Colors.red;
await tester.pumpWidget( await tester.pumpWidget(
wrap( wrap(
child: Center( child: const Center(
child: SwitchListTile( child: SwitchListTile(
value: false, value: false,
onChanged: null, onChanged: null,
title: const Text('Title'), title: Text('Title'),
tileColor: tileColor, tileColor: tileColor,
), ),
), ),
), ),
); );
expect(find.byType(Material), paints..path(color: tileColor)); final ColoredBox coloredBox = tester.firstWidget(find.byType(ColoredBox));
expect(coloredBox.color, tileColor);
}); });
testWidgets('SwitchListTile respects selectedTileColor', (WidgetTester tester) async { testWidgets('SwitchListTile respects selectedTileColor', (WidgetTester tester) async {
final Color selectedTileColor = Colors.green.shade500; const Color selectedTileColor = Colors.black;
await tester.pumpWidget( await tester.pumpWidget(
wrap( wrap(
child: Center( child: const Center(
child: SwitchListTile( child: SwitchListTile(
value: false, value: false,
onChanged: null, onChanged: null,
title: const Text('Title'), title: Text('Title'),
selected: true, selected: true,
selectedTileColor: selectedTileColor, selectedTileColor: selectedTileColor,
), ),
...@@ -394,7 +395,8 @@ void main() { ...@@ -394,7 +395,8 @@ void main() {
), ),
); );
expect(find.byType(Material), paints..path(color: selectedTileColor)); final ColoredBox coloredBox = tester.firstWidget(find.byType(ColoredBox));
expect(coloredBox.color, equals(selectedTileColor));
}); });
} }
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// 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 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
...@@ -22,14 +21,14 @@ class TestItem extends StatelessWidget { ...@@ -22,14 +21,14 @@ class TestItem extends StatelessWidget {
} }
} }
Widget buildFrame({ int? count, double? width, double? height, Axis? scrollDirection, Key? prototypeKey }) { Widget buildFrame({ int? count, double? width, double? height, Axis? scrollDirection }) {
return Directionality( return Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: CustomScrollView( child: CustomScrollView(
scrollDirection: scrollDirection ?? Axis.vertical, scrollDirection: scrollDirection ?? Axis.vertical,
slivers: <Widget>[ slivers: <Widget>[
SliverPrototypeExtentList( SliverPrototypeExtentList(
prototypeItem: TestItem(item: -1, width: width, height: height, key: prototypeKey), prototypeItem: TestItem(item: -1, width: width, height: height),
delegate: SliverChildBuilderDelegate( delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) => TestItem(item: index), (BuildContext context, int index) => TestItem(item: index),
childCount: count, childCount: count,
...@@ -137,18 +136,4 @@ void main() { ...@@ -137,18 +136,4 @@ void main() {
for (int i = 1; i < 10; i += 1) for (int i = 1; i < 10; i += 1)
expect(find.text('Item $i'), findsOneWidget); expect(find.text('Item $i'), findsOneWidget);
}); });
testWidgets('SliverPrototypeExtentList prototypeItem paint transform is zero.', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/67117
// This test ensures that the SliverPrototypeExtentList does not cause an
// assertion error when calculating the paint transform of its prototypeItem.
// The paint transform of the prototypeItem should be zero, since it is not visible.
final GlobalKey prototypeKey = GlobalKey();
await tester.pumpWidget(buildFrame(count: 20, height: 100.0, prototypeKey: prototypeKey));
final RenderObject scrollView = tester.renderObject(find.byType(CustomScrollView));
final RenderObject prototype = prototypeKey.currentContext!.findRenderObject()!;
expect(prototype.getTransformTo(scrollView), Matrix4.zero());
});
} }
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