Data Properties
Data properties are declared in initialisation code of dialogue model.
First, define some data class to play with
1
data class Country(val name: String, val region: String)
Copied!

Static definition

You can define your data inside initialisation code
1
val countries = listOf(Country("Germany", "Europe"), Country("United States", "North America"))
Copied!

Loading from external source

To load data into model data property from external source, use delegate loader.
Example of loading data from external URL providing resource of type JSON with known structure defined as data class
1
val countries by loader<List<Country>>("https://core.flowstorm.ai/file/assets/data/CountryByRegionList.json")
Copied!
If you don't know the exact structure, you can work with data as with Map objects
1
val countries by loader<List<Map<String, Any>>>("https://core.flowstorm.ai/file/assets/data/CountryByRegionList.json")
Copied!
You can also load lists of primitive values, e.g. of type String
1
val countryNames by loader<List<String>>("hhttps://core.flowstorm.ai/file/assets/data/countries.json")
Copied!
You can also use File Assets of type JSON. Just upload your file to it and get asset URL from its detail.
Last modified 10mo ago