Android 函数必须用 @Composable 标记
我有一个 @Composable 函数,可以使用 教程 与内部的单个元素完美配合。但是,通过添加 LocalInspectionMode.current
或其他元素(例如 column
),它会产生一个奇怪的错误。
@Composable
fun MessageCard(name: String){
if(LocalInspectionMode.current){
Text("Hello $name!")
} else {
Text("Goodbye $name!")
}
}
或
@Composable
fun MessageCard(msg: Message){
Column {
Text("Hello ${msg.author}!")
Text("Hello ${msg.author}!")
}
}
错误消息:
调用 @Composable 函数的函数必须用 @Composable注解
显然,该函数确实包含 @Composable
注解。 有什么帮助吗?谢谢
I have a @Composable function that works perfectly with single element inside using the tutorial. However, by adding LocalInspectionMode.current
or other elements, such as, column
, it produces a strange error.
@Composable
fun MessageCard(name: String){
if(LocalInspectionMode.current){
Text("Hello $name!")
} else {
Text("Goodbye $name!")
}
}
or
@Composable
fun MessageCard(msg: Message){
Column {
Text("Hello ${msg.author}!")
Text("Hello ${msg.author}!")
}
}
The error message:
Functions which invoke @Composable functions must be marked with the
@Composable annotation
Obviously, the function does contain the @Composable
annotation.
Any help? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论