CompositionLocal
//用于引发错误 var ActiveUser = compositionLocalOf{ 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) }