From f05a555bcba43f14fe05f5d091b501d18536493f Mon Sep 17 00:00:00 2001 From: Pierre-Louis <6655696+guidezpl@users.noreply.github.com> Date: Fri, 10 Feb 2023 18:32:43 +0100 Subject: [PATCH] Fix lerping for `NavigationRailThemeData` icon themes (#120066) * Fix lerping for NavigationRail icon themes * fix typo --- .../flutter/lib/src/material/navigation_rail_theme.dart | 6 ++++-- .../flutter/test/material/navigation_rail_theme_test.dart | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/flutter/lib/src/material/navigation_rail_theme.dart b/packages/flutter/lib/src/material/navigation_rail_theme.dart index 70178c1a58..c7417adf77 100644 --- a/packages/flutter/lib/src/material/navigation_rail_theme.dart +++ b/packages/flutter/lib/src/material/navigation_rail_theme.dart @@ -151,8 +151,10 @@ class NavigationRailThemeData with Diagnosticable { elevation: lerpDouble(a?.elevation, b?.elevation, t), unselectedLabelTextStyle: TextStyle.lerp(a?.unselectedLabelTextStyle, b?.unselectedLabelTextStyle, t), selectedLabelTextStyle: TextStyle.lerp(a?.selectedLabelTextStyle, b?.selectedLabelTextStyle, t), - unselectedIconTheme: IconThemeData.lerp(a?.unselectedIconTheme, b?.unselectedIconTheme, t), - selectedIconTheme: IconThemeData.lerp(a?.selectedIconTheme, b?.selectedIconTheme, t), + unselectedIconTheme: a?.unselectedIconTheme == null && b?.unselectedIconTheme == null + ? null : IconThemeData.lerp(a?.unselectedIconTheme, b?.unselectedIconTheme, t), + selectedIconTheme: a?.selectedIconTheme == null && b?.selectedIconTheme == null + ? null : IconThemeData.lerp(a?.selectedIconTheme, b?.selectedIconTheme, t), groupAlignment: lerpDouble(a?.groupAlignment, b?.groupAlignment, t), labelType: t < 0.5 ? a?.labelType : b?.labelType, useIndicator: t < 0.5 ? a?.useIndicator : b?.useIndicator, diff --git a/packages/flutter/test/material/navigation_rail_theme_test.dart b/packages/flutter/test/material/navigation_rail_theme_test.dart index e0c7205980..b791bf8fea 100644 --- a/packages/flutter/test/material/navigation_rail_theme_test.dart +++ b/packages/flutter/test/material/navigation_rail_theme_test.dart @@ -227,6 +227,14 @@ void main() { expect(_indicatorDecoration(tester)?.color, indicatorColor); }); + // Regression test for https://github.com/flutter/flutter/issues/118618. + testWidgets('NavigationRailThemeData lerps correctly with null iconThemes', (WidgetTester tester) async { + final NavigationRailThemeData lerp = NavigationRailThemeData.lerp(const NavigationRailThemeData(), const NavigationRailThemeData(), 0.5)!; + + expect(lerp.selectedIconTheme, isNull); + expect(lerp.unselectedIconTheme, isNull); + }); + testWidgets('Default debugFillProperties', (WidgetTester tester) async { final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); const NavigationRailThemeData().debugFillProperties(builder);