From 79dae000c801c29ea870473a8794898a86f59595 Mon Sep 17 00:00:00 2001 From: xster Date: Thu, 27 Sep 2018 11:17:00 -0700 Subject: [PATCH] Support activeIcon in CupertinoTabBar (#22323) --- .../lib/src/cupertino/bottom_tab_bar.dart | 7 +++- .../test/cupertino/bottom_tab_bar_test.dart | 33 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart b/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart index ab50764bd6..5cab1d78a8 100644 --- a/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart +++ b/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart @@ -172,7 +172,12 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget { child: Column( mainAxisAlignment: MainAxisAlignment.end, children: [ - Expanded(child: Center(child: items[index].icon)), + Expanded(child: + Center(child: active + ? items[index].activeIcon + : items[index].icon + ), + ), items[index].title, ], ), diff --git a/packages/flutter/test/cupertino/bottom_tab_bar_test.dart b/packages/flutter/test/cupertino/bottom_tab_bar_test.dart index 0835324a1d..6bdfcb6062 100644 --- a/packages/flutter/test/cupertino/bottom_tab_bar_test.dart +++ b/packages/flutter/test/cupertino/bottom_tab_bar_test.dart @@ -68,6 +68,39 @@ void main() { expect(actualActive.text.style.color, const Color(0xFF123456)); }); + testWidgets('Use active icon', (WidgetTester tester) async { + const TestImageProvider activeIcon = TestImageProvider(16, 16); + const TestImageProvider inactiveIcon = TestImageProvider(24, 24); + + await pumpWidgetWithBoilerplate(tester, MediaQuery( + data: const MediaQueryData(), + child: CupertinoTabBar( + items: const [ + BottomNavigationBarItem( + icon: ImageIcon(TestImageProvider(24, 24)), + title: Text('Tab 1'), + ), + BottomNavigationBarItem( + icon: ImageIcon(inactiveIcon), + activeIcon: ImageIcon(activeIcon), + title: Text('Tab 2'), + ), + ], + currentIndex: 1, + activeColor: const Color(0xFF123456), + inactiveColor: const Color(0xFF654321), + ), + )); + + final Image image = tester.widget(find.descendant( + of: find.widgetWithText(GestureDetector, 'Tab 2'), + matching: find.byType(Image) + )); + + expect(image.color, const Color(0xFF123456)); + expect(image.image, activeIcon); + }); + testWidgets('Adjusts height to account for bottom padding', (WidgetTester tester) async { final CupertinoTabBar tabBar = CupertinoTabBar( items: const [