Jetpack Compose Material3 の ListItem で設定画面を秒でつくる

実際、秒、ってことないけども。

まあまあ簡単で見た目も綺麗にできます。

Jetpack Compose Material3 の ListItem を使います。


@Composable
fun ListItem(
    headlineContent: @Composable () -> Unit,
    modifier: Modifier = Modifier,
    overlineContent: (@Composable () -> Unit)? = null,
    supportingContent: (@Composable () -> Unit)? = null,
    leadingContent: (@Composable () -> Unit)? = null,
    trailingContent: (@Composable () -> Unit)? = null,
    colors: ListItemColors = ListItemDefaults.colors(),
    tonalElevation: Dp = ListItemDefaults.Elevation,
    shadowElevation: Dp = ListItemDefaults.Elevation
): Unit


👉 androidx.compose.material3  |  Android Developers

Card を利用して、設定項目をグループ分けします。

👉 Card  |  Jetpack Compose  |  Android Developers

以下のようなレイアウト構成。


SettingScreen
  LazyColumn
    Card - Group
      ListItem - Clickable
      ListItem - Switch
      ListItem - Checkbox
    Card
      ListItem - Clickable
      ListItem - Switch
      ListItem - Checkbox
    ...

こう書けました。

こんな感じです。

Material3 って、今では結構使えるんですね!


【Kotlin】バージョンカタログ libs.versions.toml の記述だるくね? module 記述のほうが良くね?

なんか面倒なだけな気がしてきた。


hilt-android = { group = "com.google.dagger", name = "hilt-android", version.ref = "hilt" }
hilt-compiler = { group = "com.google.dagger", name = "hilt-compiler", version.ref = "hilt" }

group, name より、

module 記述で良くないか。


hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "hilt" }
hilt-compiler = { module = "com.google.dagger:hilt-compiler", version.ref = "hilt" }

まあ、無駄に几帳面に書いてました。

こんなにスッキリ。

👉 Pokedex/gradle/libs.versions.toml at main · skydoves/Pokedex


【Android】Hilt + KSP で error.NonExistentClass を解決するヒント - Protobuf / SQLDelight / ViewBinding / AIDL

見かけましたよね。

以下に似たようなエラー。


e: [ksp] InjectProcessingStep was unable to process 'RemoteUnfoldTransitionReceiver(boolean,java.util.concurrent.Executor)' because 'error.NonExistentClass' could not be resolved.

Dependency trace:
    => element (CLASS): com.android.systemui.unfold.progress.RemoteUnfoldTransitionReceiver
    => type (ERROR superclass): error.NonExistentClass

If type 'error.NonExistentClass' is a generated type, check above for compilation errors that may have prevented the type from being generated. Otherwise, ensure that type 'error.NonExistentClass' is on your classpath.
e: [ksp] InjectProcessingStep was unable to process 'UnfoldTransitionProgressForwarder()' because 'error.NonExistentClass' could not be resolved.

Dependency trace:
    => element (CLASS): com.android.systemui.unfold.progress.UnfoldTransitionProgressForwarder
    => type (ERROR superclass): error.NonExistentClass

If type 'error.NonExistentClass' is a generated type, check above for compilation errors that may have prevented the type from being generated. Otherwise, ensure that type 'error.NonExistentClass' is on your classpath.
e: [ksp] ComponentProcessingStep was unable to process 'com.android.systemui.unfold.RemoteUnfoldSharedComponent' because 'error.NonExistentClass' could not be resolved.

Dependency trace:
    => element (CLASS): com.android.systemui.unfold.progress.RemoteUnfoldTransitionReceiver
    => type (ERROR superclass): error.NonExistentClass

If type 'error.NonExistentClass' is a generated type, check above for compilation errors that may have prevented the type from being generated. Otherwise, ensure that type 'error.NonExistentClass' is on your classpath.
e: Error occurred in KSP, check log for detail

私は、SDKバージョンアップ時に SQLDelight で出会いましたが以下で回避。


// bottom of app/build.gradle.kts

androidComponents {
  onVariants(selector().all()) { variant ->
    afterEvaluate {
      val capName = variant.name.capitalize()
      tasks.getByName<KotlinCompile>("ksp${capName}Kotlin") {
        setSource(tasks.getByName("generate${capName}DatabaseInterface").outputs)
      }
    }
  }
}

👉 [ksp] InjectProcessingStep was unable to process a class which extends Binder Stub because 'error.NonExistentClass' could not be resolved. · Issue #4158 · google/dagger

こんな「とりあえず回避」ってのよくありますが

対応コードが溜まっていくと後々意味不明になるので

なんか嫌ですけど、

仕方ないんですよね。

👉 SqlDelight inconsistency with KSP · Issue #5473 · sqldelight/sqldelight
👉 KSP Compilation Failure: Unresolved `error.NonExistentClass` during `MarketDaoImpl` and `LocalDatasourceModule` processing · Issue #2092 · google/ksp
👉 SQLDelight 2.0 Tasks · Issue #2694 · sqldelight/sqldelight