Vasily Scherbakov
09/04/2021, 9:06 AMclass MainView : KComposite() {
private val apiClient: ScenarioServiceClient = ScenarioServiceClientImpl("<http://localhost:5000>");
private val root = ui {
verticalLayout {
horizontalLayout {
div{
addClassName("centered-content")
apiClient.getAvailableScenarios()
.forEach { scenario -> scenarioItemView(scenario) }
}
}
}
}
This is how i use ktor:
class ScenarioServiceClientImpl(private val baseUrl: String) : ScenarioServiceClient {
private val restClient: HttpClient = HttpClient(Apache)
override suspend fun getAvailableScenarios() : List<ScenarioViewModel>{
val scenarios = restClient.get<List<ScenarioViewModel>>("${baseUrl}/scenarios")}}
May be there is some way to invoke api call without suspend?Didier Villevalois
09/04/2021, 9:24 PMvar availableScenarios: List<ScenarioViewModel>? = null
3. you can then add an init { launch { availableScenarios = apiClient.getAvailableScenarios() } }
block
4. finally, in your div
, you just have to test whether the availableScenarios
is null or not, and display either a loading widget or the result.
All this will only work, if you can dynamically add children to your ui
tree and that, somehow, KComposite rebuilds it view.
Hope this helps.Aleksei Tirman [JB]
09/06/2021, 10:29 AMVasily Scherbakov
09/07/2021, 6:02 PM