Skip to content

Commit 12368bd

Browse files
authored
fix: remove debug log spam and setGravity warnings (#564)
- Remove debug log statement that was causing D/KARTHIK spam - Only call setGravity() on custom toasts with background color to avoid Android API 30+ warnings on text toasts
1 parent fcf8db9 commit 12368bd

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

android/src/main/kotlin/io/github/ponnamkarthik/toast/fluttertoast/MethodCallHandlerImpl.kt

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ internal class MethodCallHandlerImpl(private var context: Context) : MethodCallH
7676
}
7777
mToast?.view = layout
7878
} else {
79-
Log.d("KARTHIK", "showToast: $bgcolor $textcolor $fontSize $fontAsset")
8079
mToast = Toast.makeText(context, mMessage, mDuration)
8180
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
8281
val textView: TextView = mToast?.view!!.findViewById(android.R.id.message)
@@ -94,19 +93,23 @@ internal class MethodCallHandlerImpl(private var context: Context) : MethodCallH
9493
}
9594
}
9695

97-
try {
98-
when (mGravity) {
99-
Gravity.CENTER -> {
100-
mToast?.setGravity(mGravity, 0, 0,)
101-
}
102-
Gravity.TOP -> {
103-
mToast?.setGravity(mGravity, 0, 100,)
104-
}
105-
else -> {
106-
mToast?.setGravity(mGravity, 0, 100,)
96+
// Only set gravity on custom toasts (with background color)
97+
// setGravity() on text toasts causes warnings in Android API 30+
98+
if (bgcolor != null) {
99+
try {
100+
when (mGravity) {
101+
Gravity.CENTER -> {
102+
mToast?.setGravity(mGravity, 0, 0,)
103+
}
104+
Gravity.TOP -> {
105+
mToast?.setGravity(mGravity, 0, 100,)
106+
}
107+
else -> {
108+
mToast?.setGravity(mGravity, 0, 100,)
109+
}
107110
}
108-
}
109-
} catch (e: Exception,) { }
111+
} catch (e: Exception,) { }
112+
}
110113

111114
if (context is Activity) {
112115
(context as Activity).runOnUiThread { mToast?.show() }

0 commit comments

Comments
 (0)