diff --git a/packages/flutter/lib/src/cupertino/form_section.dart b/packages/flutter/lib/src/cupertino/form_section.dart index a381775ff9..c3d662575a 100644 --- a/packages/flutter/lib/src/cupertino/form_section.dart +++ b/packages/flutter/lib/src/cupertino/form_section.dart @@ -11,12 +11,6 @@ import 'list_section.dart'; // iOS 14.2 SDK. const EdgeInsetsDirectional _kFormDefaultInsetGroupedRowsMargin = EdgeInsetsDirectional.fromSTEB(20.0, 0.0, 20.0, 10.0); -// Standard header margin, determined from SwiftUI's Forms in iOS 14.2 SDK. -const EdgeInsetsDirectional _kFormDefaultHeaderMargin = EdgeInsetsDirectional.fromSTEB(20.0, 16.0, 20.0, 10.0); - -// Standard footer margin, determined from SwiftUI's Forms in iOS 14.2 SDK. -const EdgeInsetsDirectional _kFormDefaultFooterMargin = EdgeInsetsDirectional.fromSTEB(20.0, 0.0, 20.0, 10.0); - /// An iOS-style form section. /// /// The base constructor for [CupertinoFormSection] constructs an @@ -205,10 +199,7 @@ class CupertinoFormSection extends StatelessWidget { fontSize: 13.0, color: CupertinoColors.secondaryLabel.resolveFrom(context), ), - child: Padding( - padding: _kFormDefaultHeaderMargin, - child: header, - )); + child: header!); final Widget? footerWidget = footer == null ? null @@ -217,10 +208,7 @@ class CupertinoFormSection extends StatelessWidget { fontSize: 13.0, color: CupertinoColors.secondaryLabel.resolveFrom(context), ), - child: Padding( - padding: _kFormDefaultFooterMargin, - child: footer, - )); + child: footer!); return _type == CupertinoListSectionType.base ? CupertinoListSection( diff --git a/packages/flutter/test/cupertino/form_section_test.dart b/packages/flutter/test/cupertino/form_section_test.dart index da86fb9e89..1909e68b1c 100644 --- a/packages/flutter/test/cupertino/form_section_test.dart +++ b/packages/flutter/test/cupertino/form_section_test.dart @@ -168,4 +168,57 @@ void main() { final Iterable renderClips = tester.allRenderObjects.whereType(); expect(renderClips, isEmpty); }); + + testWidgetsWithLeakTracking('Does not double up padding on header', (WidgetTester tester) async { + const Widget header = Text('Header'); + + await tester.pumpWidget( + CupertinoApp( + home: Center( + child: CupertinoFormSection( + header: header, + children: [CupertinoTextFormFieldRow()], + ), + ), + ), + ); + + expect(tester.getTopLeft(find.byWidget(header)), const Offset(20, 22)); + }); + + testWidgetsWithLeakTracking('Does not double up padding on footer', (WidgetTester tester) async { + const Widget footer = Text('Footer'); + + await tester.pumpWidget( + CupertinoApp( + home: Center( + child: CupertinoFormSection( + footer: footer, + children: [CupertinoTextFormFieldRow()], + ), + ), + ), + ); + + expect(tester.getTopLeft(find.byWidget(footer)), offsetMoreOrLessEquals(const Offset(20, 65), epsilon: 1)); + }); + + testWidgetsWithLeakTracking('Sets custom margin', (WidgetTester tester) async { + final Widget child = CupertinoTextFormFieldRow(); + + const double margin = 35; + + await tester.pumpWidget( + CupertinoApp( + home: Center( + child: CupertinoFormSection( + margin: const EdgeInsets.all(margin), + children: [child], + ), + ), + ), + ); + + expect(tester.getTopLeft(find.byWidget(child)), offsetMoreOrLessEquals(const Offset(margin, 22 + margin), epsilon: 1)); + }); } diff --git a/packages/flutter/test/cupertino/list_section_test.dart b/packages/flutter/test/cupertino/list_section_test.dart index 0119947b5b..0f81a98977 100644 --- a/packages/flutter/test/cupertino/list_section_test.dart +++ b/packages/flutter/test/cupertino/list_section_test.dart @@ -223,4 +223,44 @@ void main() { } } }); + + testWidgetsWithLeakTracking('does not show margin by default', (WidgetTester tester) async { + const Widget child = CupertinoListTile(title: Text('CupertinoListTile')); + + await tester.pumpWidget( + CupertinoApp( + home: Center( + child: CupertinoListSection( + header: const Text('Header'), + children: const [ + child, + ], + ), + ), + ), + ); + + expect(tester.getTopLeft(find.byWidget(child)), offsetMoreOrLessEquals(const Offset(0, 41), epsilon: 1)); + }); + + testWidgetsWithLeakTracking('shows custom margin', (WidgetTester tester) async { + const Widget child = CupertinoListTile(title: Text('CupertinoListTile')); + const double margin = 10; + + await tester.pumpWidget( + CupertinoApp( + home: Center( + child: CupertinoListSection( + header: const Text('Header'), + margin: const EdgeInsets.all(margin), + children: const [ + child, + ], + ), + ), + ), + ); + + expect(tester.getTopLeft(find.byWidget(child)), offsetMoreOrLessEquals(const Offset(margin, 41 + margin), epsilon: 1)); + }); }