Muhammad Zaryab Rafique
04/01/2021, 4:13 PMGabriel Melo
04/01/2021, 4:22 PMMuhammad Zaryab Rafique
04/01/2021, 4:23 PMBlaž Vantur
04/01/2021, 4:27 PMval locationCoordinates = Coordinates(cords[0].latitude, cords[0].longitude)
That happens because you have set an empty list as a default value for your coords
list in MainComponent in this line of code:
val cords: List<Locator.Coordinate> by mainViewModel.myCords.observeAsState(listOf)
.
I suggest for you to add if check before accessing elements from that list to prevent accessing an empty list.Muhammad Zaryab Rafique
04/01/2021, 4:32 PMColton Idle
04/01/2021, 5:08 PMMuhammad Zaryab Rafique
04/01/2021, 5:46 PMMuhammad Zaryab Rafique
04/02/2021, 3:02 AMprivate var gpsTracker: GPSTracker? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Locator.requestPermissionLocation(this)
gpsTracker = GPSTracker(applicationContext)
setContent {
RukuhTheme {
Surface(color = MaterialTheme.colors.background) {
App(gpsTracker!!)
}
}
}
}
Muhammad Zaryab Rafique
04/02/2021, 3:04 AM@Composable
fun App(gpsTracker: GPSTracker) {
val doubleLatitude: Double?
val doubleLongitude: Double?
doubleLatitude = gpsTracker.getLatitude()
doubleLongitude = gpsTracker.getLongitude()
if (doubleLatitude != 0.0 && doubleLongitude != 0.0)
MainContent(doubleLatitude, doubleLongitude)
else {
Text(text = "Empty List")
}
}