diff --git a/packages/flutter/lib/src/material/snack_bar.dart b/packages/flutter/lib/src/material/snack_bar.dart index 525fcedb04..2ca6e8a0ca 100644 --- a/packages/flutter/lib/src/material/snack_bar.dart +++ b/packages/flutter/lib/src/material/snack_bar.dart @@ -296,10 +296,29 @@ class SnackBar extends StatefulWidget { /// The amount of padding to apply to the snack bar's content and optional /// action. /// - /// If this property is null, then the default depends on the [behavior] and - /// the presence of an [action]. The start padding is 24 if [behavior] is - /// [SnackBarBehavior.fixed] and 16 if it is [SnackBarBehavior.floating]. If - /// there is no [action], the same padding is added to the end. + /// If this property is null, the default padding values for: + /// + /// * [content] + /// * Top and bottom paddings are 14. + /// * Left padding is 24 if [behavior] is [SnackBarBehavior.fixed], + /// 16 if [behavior] is [SnackBarBehavior.floating] + /// * Right padding is same as start padding if there is no [action], otherwise 0. + /// * [action] + /// * Top and bottom paddings are 14 + /// * Left and right paddings are half of [content]'s left padding. + /// + /// If this property is not null, the padding assignment for: + /// + /// * [content] + /// * Left, top and bottom paddings are assigned normally. + /// * Right padding is assigned normally if there is no [action], otherwise 0. + /// * [action] + /// * Left padding is replaced with half value of right padding. + /// * Top and bottom paddings are assigned normally. + /// * Right padding has an additional half value of right padding. + /// ```dart + /// right + (right / 2) + /// ``` final EdgeInsetsGeometry? padding; /// The width of the snack bar. @@ -523,7 +542,7 @@ class _SnackBarState extends State { children: [ Expanded( child: Container( - padding: const EdgeInsets.symmetric(vertical: _singleLineVerticalPadding), + padding: widget.padding == null ? const EdgeInsets.symmetric(vertical: _singleLineVerticalPadding) : null, child: DefaultTextStyle( style: contentTextStyle!, child: widget.content, diff --git a/packages/flutter/test/material/snack_bar_test.dart b/packages/flutter/test/material/snack_bar_test.dart index ae13588f85..a0ef2bb09f 100644 --- a/packages/flutter/test/material/snack_bar_test.dart +++ b/packages/flutter/test/material/snack_bar_test.dart @@ -978,9 +978,8 @@ void main() { final Offset snackBarTopRight = tester.getTopRight(materialFinder); expect(textBottomLeft.dx - snackBarBottomLeft.dx, padding); expect(snackBarTopRight.dx - textTopRight.dx, padding); - // The text is given a vertical padding of 14 already. - expect(snackBarBottomLeft.dy - textBottomLeft.dy, padding + 14); - expect(textTopRight.dy - snackBarTopRight.dy, padding + 14); + expect(snackBarBottomLeft.dy - textBottomLeft.dy, padding); + expect(textTopRight.dy - snackBarTopRight.dy, padding); }); testWidgets('Snackbar width can be customized', (WidgetTester tester) async {