Unverified Commit 109893c6 authored by rami-a's avatar rami-a Committed by GitHub

[Material] Add contentPadding property to SwitchListTile (#38709)

parent 2daab305
......@@ -279,6 +279,7 @@ class SwitchListTile extends StatelessWidget {
this.subtitle,
this.isThreeLine = false,
this.dense,
this.contentPadding,
this.secondary,
this.selected = false,
}) : _switchListTileType = _SwitchListTileType.material,
......@@ -310,6 +311,7 @@ class SwitchListTile extends StatelessWidget {
this.subtitle,
this.isThreeLine = false,
this.dense,
this.contentPadding,
this.secondary,
this.selected = false,
}) : _switchListTileType = _SwitchListTileType.adaptive,
......@@ -409,6 +411,15 @@ class SwitchListTile extends StatelessWidget {
/// If this property is null then its value is based on [ListTileTheme.dense].
final bool dense;
/// The tile's internal padding.
///
/// Insets a [SwitchListTile]'s contents: its [title], [subtitle],
/// [secondary], and [Switch] widgets.
///
/// If null, [ListTile]'s default of `EdgeInsets.symmetric(horizontal: 16.0)`
/// is used.
final EdgeInsetsGeometry contentPadding;
/// Whether to render icons and text in the [activeColor].
///
/// No effort is made to automatically coordinate the [selected] state and the
......@@ -462,6 +473,7 @@ class SwitchListTile extends StatelessWidget {
trailing: control,
isThreeLine: isThreeLine,
dense: dense,
contentPadding: contentPadding,
enabled: onChanged != null,
onTap: onChanged != null ? () { onChanged(!value); } : null,
selected: selected,
......
......@@ -100,4 +100,45 @@ void main() {
await tester.tap(find.byType(SwitchListTile));
expect(value, isFalse);
});
testWidgets('SwitchListTile contentPadding', (WidgetTester tester) async {
Widget buildFrame(TextDirection textDirection) {
return MediaQuery(
data: const MediaQueryData(
padding: EdgeInsets.zero,
textScaleFactor: 1.0,
),
child: Directionality(
textDirection: textDirection,
child: Material(
child: Container(
alignment: Alignment.topLeft,
child: SwitchListTile(
contentPadding: const EdgeInsetsDirectional.only(
start: 10.0,
end: 20.0,
top: 30.0,
bottom: 40.0,
),
secondary: const Text('L'),
title: const Text('title'),
value: true,
onChanged: (bool selected) {},
),
),
),
),
);
}
await tester.pumpWidget(buildFrame(TextDirection.ltr));
expect(tester.getTopLeft(find.text('L')).dx, 10.0); // contentPadding.start = 10
expect(tester.getTopRight(find.byType(Switch)).dx, 780.0); // 800 - contentPadding.end
await tester.pumpWidget(buildFrame(TextDirection.rtl));
expect(tester.getTopLeft(find.byType(Switch)).dx, 20.0); // contentPadding.end = 20
expect(tester.getTopRight(find.text('L')).dx, 790.0); // 800 - contentPadding.start
});
}
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