From 18fb916869ff72cbfdbec9870518047a1f6d5153 Mon Sep 17 00:00:00 2001 From: AhmedTalib Date: Thu, 7 Nov 2024 11:57:57 +0400 Subject: [PATCH] In the previous code , currentTopLevelDestination would be momentarily null. --- .../com/google/samples/apps/nowinandroid/ui/NiaAppState.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/google/samples/apps/nowinandroid/ui/NiaAppState.kt b/app/src/main/kotlin/com/google/samples/apps/nowinandroid/ui/NiaAppState.kt index 75a294c01..9a205ff4e 100644 --- a/app/src/main/kotlin/com/google/samples/apps/nowinandroid/ui/NiaAppState.kt +++ b/app/src/main/kotlin/com/google/samples/apps/nowinandroid/ui/NiaAppState.kt @@ -89,8 +89,11 @@ class NiaAppState( val currentTopLevelDestination: TopLevelDestination? @Composable get() { - return TopLevelDestination.entries.firstOrNull { topLevelDestination -> - currentDestination?.hasRoute(route = topLevelDestination.route) ?: false + val currentDestination = currentDestination + return remember(currentDestination) { + TopLevelDestination.entries.firstOrNull { topLevelDestination -> + currentDestination?.hasRoute(route = topLevelDestination.route) ?: false + } } }