From d65bdb9b542d158f477b57fb013969aead02b14e Mon Sep 17 00:00:00 2001 From: AhmedTalib Date: Thu, 7 Nov 2024 12:50:56 +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 75a294c01c..9a205ff4ee 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 + } } }