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 {
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<int>? 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,
......
......@@ -327,6 +327,49 @@ Future<void> 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>[
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(),
......
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