Unverified Commit aac68515 authored by najeira's avatar najeira Committed by GitHub

Add CupertinoTabBar.height (#72919)

parent db78a2e5
...@@ -65,6 +65,7 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget { ...@@ -65,6 +65,7 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget {
this.activeColor, this.activeColor,
this.inactiveColor = _kDefaultTabBarInactiveColor, this.inactiveColor = _kDefaultTabBarInactiveColor,
this.iconSize = 30.0, this.iconSize = 30.0,
this.height = _kTabBarHeight,
this.border = const Border( this.border = const Border(
top: BorderSide( top: BorderSide(
color: _kDefaultTabBarBorderColor, color: _kDefaultTabBarBorderColor,
...@@ -79,6 +80,7 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget { ...@@ -79,6 +80,7 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget {
assert(currentIndex != null), assert(currentIndex != null),
assert(0 <= currentIndex && currentIndex < items.length), assert(0 <= currentIndex && currentIndex < items.length),
assert(iconSize != null), assert(iconSize != null),
assert(height != null && height >= 0.0),
assert(inactiveColor != null), assert(inactiveColor != null),
super(key: key); super(key: key);
...@@ -129,13 +131,18 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget { ...@@ -129,13 +131,18 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget {
/// Must not be null. /// Must not be null.
final double iconSize; 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 border of the [CupertinoTabBar].
/// ///
/// The default value is a one physical pixel top border with grey color. /// The default value is a one physical pixel top border with grey color.
final Border? border; final Border? border;
@override @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 /// Indicates whether the tab bar is fully opaque or can have contents behind
/// it show through it. /// it show through it.
...@@ -178,7 +185,7 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget { ...@@ -178,7 +185,7 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget {
color: backgroundColor, color: backgroundColor,
), ),
child: SizedBox( child: SizedBox(
height: _kTabBarHeight + bottomPadding, height: height + bottomPadding,
child: IconTheme.merge( // Default with the inactive state. child: IconTheme.merge( // Default with the inactive state.
data: IconThemeData(color: inactive, size: iconSize), data: IconThemeData(color: inactive, size: iconSize),
child: DefaultTextStyle( // Default with the inactive state. child: DefaultTextStyle( // Default with the inactive state.
...@@ -285,6 +292,7 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget { ...@@ -285,6 +292,7 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget {
Color? activeColor, Color? activeColor,
Color? inactiveColor, Color? inactiveColor,
double? iconSize, double? iconSize,
double? height,
Border? border, Border? border,
int? currentIndex, int? currentIndex,
ValueChanged<int>? onTap, ValueChanged<int>? onTap,
...@@ -296,6 +304,7 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget { ...@@ -296,6 +304,7 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget {
activeColor: activeColor ?? this.activeColor, activeColor: activeColor ?? this.activeColor,
inactiveColor: inactiveColor ?? this.inactiveColor, inactiveColor: inactiveColor ?? this.inactiveColor,
iconSize: iconSize ?? this.iconSize, iconSize: iconSize ?? this.iconSize,
height: height ?? this.height,
border: border ?? this.border, border: border ?? this.border,
currentIndex: currentIndex ?? this.currentIndex, currentIndex: currentIndex ?? this.currentIndex,
onTap: onTap ?? this.onTap, onTap: onTap ?? this.onTap,
......
...@@ -327,6 +327,49 @@ Future<void> main() async { ...@@ -327,6 +327,49 @@ Future<void> main() async {
expect(tester.getSize(find.byType(CupertinoTabBar)).height, 90.0); 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>[
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 { testWidgets('Opaque background does not add blur effects', (WidgetTester tester) async {
await pumpWidgetWithBoilerplate(tester, MediaQuery( await pumpWidgetWithBoilerplate(tester, MediaQuery(
data: const MediaQueryData(), data: const MediaQueryData(),
......
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