Android Studio throws an Unresolved Reference
error for ScaffoldState
with Material3
. How can I make it work?
import androidx.compose.foundation.clickable
import androidx.compose.material3.*
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.navigation.NavController
import kotlinx.coroutines.launch
@Composable
fun CustomAppBar(
title: String,
backGroundColor: Color = Color.White,
actions: @Composable () -> Unit = { },
scaffoldState: ScaffoldState? = null, // Errors here...
navController: NavController,
) {
val scope = rememberCoroutineScope()
SmallTopAppBar(
title = {
Text(
title,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
},
colors = TopAppBarDefaults.smallTopAppBarColors(
containerColor = containerBackGroundColor,
titleContentColor = titleContentColor
),
navigationIcon = if (navController?.previousBackStackEntry != null) {
{
IconButton(onClick = { navController.navigateUp() }) {
Icon(
imageVector = Icons.Filled.ArrowBack,
contentDescription = "Back"
)
}
}
} else {
{
IconButton(onClick = {
scope.launch {
scaffoldState?.drawerState?.open()
}
}) {
Icon(
Icons.Filled.Menu,
contentDescription = "Nav drawer icon",
)
}
}
},
actions = {
actions()
}
)
}
Dependencies
implementation "androidx.core:core-ktx:1.8.0"
implementation "androidx.compose.ui:ui:1.2.1"
implementation "androidx.compose.material3:material3:1.0.0-beta01"
implementation "androidx.compose.ui:ui-tooling-preview:1.2.1"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1"
implementation "androidx.activity:activity-compose:1.3.1"
implementation "androidx.compose.compiler:compiler:1.3.0"
implementation "androidx.navigation:navigation-runtime:2.5.1"
implementation "com.google.accompanist:accompanist-navigation-animation:0.23.1"
1.3.0-alpha02
forandroidx.compose.ui:ui
andandroidx.compose.ui:ui-tooling-preview
,1.6.0-alpha05
forandroidx.activity:activity-compose
and1.0.0-alpha15
forandroidx.compose.material3:material3
(there may be newer versions, haven't updated yet). And...0.26.0-alpha
is my accompanist version too; the non material 3 version is1.7.0-alpha03
(forcom.google.android.material:material
) and..1.9.0-alpha05
is ` androidx.core:core-ktx:`. Using Gradle 7.2.1. I'm sure I'm not on the latest. Targeting API 32 / Kotlin 1.7.10. – Bowing