CompositionLocal
//用于引发错误 放在全局 var ActiveUser = compositionLocalOf<String> { error("No active user found!") } //使用 中间组件不需要知道该CompositionLocal值, CompositionLocalProvider(ActiveUser provides "string") { SomeScreen() } @Composable fun SomeScreen() { User() } @Composable fun User() { Text( ActiveUser.current , style = MaterialTheme.typography.body2) }