Code Snippets Kotlin

Short texts Kotlin 🧑‍💻 Code snippets Kotlin ✍️ Reading lists Kotlin 👀

restricting map to bounds. Gist #2

map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0), object : MapboxMap.CancelableCallback { override fun onCancel() {} override fun onFinish() { map.setMinZoomPreference(map.cameraPosition.zoom) map.limitViewToBounds(bounds) map.addOnScaleListener(object : MapboxMap.OnScaleListener { override fun onScaleBegin(detector: StandardScaleGestureDetector) {} override fun onScale(detector: StandardScaleGestureDetector) { map.limitViewToBounds(bounds) } override fun onScaleEnd(detector: StandardScaleGestureDetector) {} }) map.addOnCameraIdleListener { map.limitViewToBounds(bounds) } } })

flutter-food-V1

# Miscellaneous *.class *.log *.pyc *.swp .DS_Store .atom/ .buildlog/ .history .svn/ # IntelliJ related *.iml *.ipr *.iws .idea/ # The .vscode folder contains launch configuration and tasks you configure in # VS Code which you may wish to be included in version control, so this line # is commented out by default. #.vscode/ # Flutter/Dart/Pub […]

nullSafetyException.kt

fun main() { //val names = listOf(“ahmed”, “khaled”, “rakan”) // val x = names.getOrElse(3){ // “you dont have index number $it” // } // println(x) val numbers = listOf(22,18,25) val y = numbers.getOrNull(4) // println(y) // val nums = mutableListOf(15,90,10) // println(nums) // nums.add(1,99) // println(nums) val names = mutableListOf(“anas”,”khaled”, “ahmed”) names.add(1,”rakan”) //println(names) names.add(2,”mohmmed”) // […]

Handling Button visibility

/**Is visible when toNight is null**/ val startButtonVisible = Transformations.map(toNight){ it == null } /**Is visible when toNight is not null**/ val stopButtonVisible = Transformations.map(toNight){ it != null } /**Is visible when there are nights to clear**/ val clearButtonVisible = Transformations.map(nights){ it?.isNotEmpty() } /**Add this in XML to handle Buttons visibility**/ /*android:enabled=”@{sleepTrackerViewModel.startButtonVisible}” android:enabled=”@{sleepTrackerViewModel.stopButtonVisible}” android:enabled=”@{sleepTrackerViewModel.clearButtonVisible}”*/