I want to make a list of bots that I get from my database in firebase, but I don't know why the text() of BotList() are not shown on the screen, although the implementation seems correct, thank you very much.
class DiscoverActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
FluctusTheme {
val navController = rememberNavController()
DiscoverActivityUI(navController)
}
}
}
}
@SuppressLint("UnusedMaterialScaffoldPaddingParameter")
@Composable
fun DiscoverActivityUI(navController: NavController?) {
val systemUiController = rememberSystemUiController()
DisposableEffect(systemUiController) {
systemUiController.setStatusBarColor(
color = backgroundColor,
)
systemUiController.setNavigationBarColor(
color = white
)
onDispose {}
}
Scaffold(
modifier = Modifier.fillMaxSize(),
bottomBar = { BottomNavigationBar(navController = navController) }
) {
Surface(
color = backgroundColor,
modifier = Modifier.fillMaxSize()
) {
** BotList() **
}
}
}
@Composable
fun BotList() {
val botData = BotData()
LaunchedEffect(Unit) {
botData.mutableBotList.clear()
botData.updateBotList()
}
LazyColumn(
modifier = Modifier.fillMaxWidth()
) {
**items(botData.mutableBotList) { bot ->
bot.name?.let { Text(text = it, style = TextStyle(fontSize = 16.sp)) }
bot.type?.let { Text(text = it, style = TextStyle(fontSize = 14.sp)) }
bot.profit_percent?.let { Text(text = it, style = TextStyle(fontSize = 12.sp)) }**
}
}
}
class BotData {
var fireStoreInstance = FirebaseFirestore.getInstance()
data class Bots(
val name: String?,
val type: String?,
val profit_percent: String?,
val isOnCurrentAccount: Boolean?
)
fun updateBotList() {
fireStoreInstance.collection("marketplace").get().addOnCompleteListener {
if(it.isSuccessful) {
for(document in it.result) {
val name = document.getString("name")
val type = document.getString("type")
val profit_percent = document.getString("profit_percent")
val newBot = Bots(
name = name,
type = type,
profit_percent = profit_percent,
isOnCurrentAccount = false
)
mutableBotList.add(newBot)
println(mutableBotList)
}
} else {
println("hubo un error")
}
}
}
val mutableBotList = mutableListOf<Bots>()
}
texts in the lazy columns dont showing in the screen, although the implementation seems correct, thank you very much.