Use application context to create toast

This commit is contained in:
Ivan Iskandar 2022-08-14 19:20:23 +07:00
parent 5f378e28b6
commit 63cc2bf917
No known key found for this signature in database
GPG Key ID: 2C57784F9E46D60D

View File

@ -69,7 +69,7 @@ fun Context.toast(@StringRes resource: Int, duration: Int = Toast.LENGTH_SHORT,
* @param duration the duration of the toast. Defaults to short.
*/
fun Context.toast(text: String?, duration: Int = Toast.LENGTH_SHORT, block: (Toast) -> Unit = {}): Toast {
return Toast.makeText(this, text.orEmpty(), duration).also {
return Toast.makeText(applicationContext, text.orEmpty(), duration).also {
block(it)
it.show()
}