diff --git a/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart b/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart index a22eb8ffa2..47d357531f 100644 --- a/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart +++ b/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart @@ -65,6 +65,7 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget { this.activeColor, this.inactiveColor = _kDefaultTabBarInactiveColor, this.iconSize = 30.0, + this.height = _kTabBarHeight, this.border = const Border( top: BorderSide( color: _kDefaultTabBarBorderColor, @@ -79,6 +80,7 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget { assert(currentIndex != null), assert(0 <= currentIndex && currentIndex < items.length), assert(iconSize != null), + assert(height != null && height >= 0.0), assert(inactiveColor != null), super(key: key); @@ -129,13 +131,18 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget { /// Must not be null. final double iconSize; + /// The height of the [CupertinoTabBar]. + /// + /// Defaults to 50.0. Must not be null. + final double height; + /// The border of the [CupertinoTabBar]. /// /// The default value is a one physical pixel top border with grey color. final Border? border; @override - Size get preferredSize => const Size.fromHeight(_kTabBarHeight); + Size get preferredSize => Size.fromHeight(height); /// Indicates whether the tab bar is fully opaque or can have contents behind /// it show through it. @@ -178,7 +185,7 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget { color: backgroundColor, ), child: SizedBox( - height: _kTabBarHeight + bottomPadding, + height: height + bottomPadding, child: IconTheme.merge( // Default with the inactive state. data: IconThemeData(color: inactive, size: iconSize), child: DefaultTextStyle( // Default with the inactive state. @@ -285,6 +292,7 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget { Color? activeColor, Color? inactiveColor, double? iconSize, + double? height, Border? border, int? currentIndex, ValueChanged? onTap, @@ -296,6 +304,7 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget { activeColor: activeColor ?? this.activeColor, inactiveColor: inactiveColor ?? this.inactiveColor, iconSize: iconSize ?? this.iconSize, + height: height ?? this.height, border: border ?? this.border, currentIndex: currentIndex ?? this.currentIndex, onTap: onTap ?? this.onTap, diff --git a/packages/flutter/test/cupertino/bottom_tab_bar_test.dart b/packages/flutter/test/cupertino/bottom_tab_bar_test.dart index d8d781f02b..f024aba864 100644 --- a/packages/flutter/test/cupertino/bottom_tab_bar_test.dart +++ b/packages/flutter/test/cupertino/bottom_tab_bar_test.dart @@ -327,6 +327,49 @@ Future main() async { expect(tester.getSize(find.byType(CupertinoTabBar)).height, 90.0); }); + testWidgets('Set custom height', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/51704 + const double tabBarHeight = 56.0; + final CupertinoTabBar tabBar = CupertinoTabBar( + height: tabBarHeight, + items: [ + BottomNavigationBarItem( + icon: ImageIcon(MemoryImage(Uint8List.fromList(kTransparentImage))), + label: 'Aka', + ), + BottomNavigationBarItem( + icon: ImageIcon(MemoryImage(Uint8List.fromList(kTransparentImage))), + label: 'Shiro', + ), + ], + ); + + // Verify height with no bottom padding. + await pumpWidgetWithBoilerplate(tester, MediaQuery( + data: const MediaQueryData(), + child: CupertinoTabScaffold( + tabBar: tabBar, + tabBuilder: (BuildContext context, int index) { + return const Placeholder(); + }, + ), + )); + expect(tester.getSize(find.byType(CupertinoTabBar)).height, tabBarHeight); + + // Verify height with bottom padding. + const double bottomPadding = 40.0; + await pumpWidgetWithBoilerplate(tester, MediaQuery( + data: const MediaQueryData(padding: EdgeInsets.only(bottom: bottomPadding)), + child: CupertinoTabScaffold( + tabBar: tabBar, + tabBuilder: (BuildContext context, int index) { + return const Placeholder(); + }, + ), + )); + expect(tester.getSize(find.byType(CupertinoTabBar)).height, tabBarHeight + bottomPadding); + }); + testWidgets('Opaque background does not add blur effects', (WidgetTester tester) async { await pumpWidgetWithBoilerplate(tester, MediaQuery( data: const MediaQueryData(),