@@ -53,6 +53,7 @@ import androidx.compose.ui.text.font.FontWeight
5353import androidx.compose.ui.tooling.preview.Preview
5454import androidx.compose.ui.unit.dp
5555import androidx.compose.ui.unit.sp
56+ import com.smarttoolfactory.tutorial1_1basics.isInPreview
5657import com.smarttoolfactory.tutorial1_1basics.ui.components.StyleableTutorialText
5758import com.smarttoolfactory.tutorial1_1basics.ui.components.TutorialHeader
5859import com.smarttoolfactory.tutorial1_1basics.ui.components.TutorialText2
@@ -100,12 +101,15 @@ private fun SnackBarExample() {
100101
101102 TutorialText2 (text = " Action SnackBar" )
102103 val context = LocalContext .current
104+ val isInPreview = isInPreview
103105 Snackbar (modifier = Modifier .padding(4 .dp),
104106 action = {
105107 Text (
106108 text = " Action" ,
107109 modifier = Modifier .clickable {
108- Toast .makeText(context, " Action is clicked" , Toast .LENGTH_SHORT ).show()
110+ if (! isInPreview) {
111+ Toast .makeText(context, " Action is clicked" , Toast .LENGTH_SHORT ).show()
112+ }
109113 })
110114 }) {
111115 Text (" Action Snackbar" )
@@ -118,7 +122,9 @@ private fun SnackBarExample() {
118122 Text (text = " Action" ,
119123 color = Color (0xffCE93D8 ),
120124 modifier = Modifier .clickable {
121- Toast .makeText(context, " Action is clicked" , Toast .LENGTH_SHORT ).show()
125+ if (! isInPreview) {
126+ Toast .makeText(context, " Action is clicked" , Toast .LENGTH_SHORT ).show()
127+ }
122128 }
123129 )
124130 }) {
@@ -137,7 +143,9 @@ private fun SnackBarExample() {
137143 Text (
138144 text = " Action" ,
139145 modifier = Modifier .clickable {
140- Toast .makeText(context, " Action is clicked" , Toast .LENGTH_SHORT ).show()
146+ if (! isInPreview) {
147+ Toast .makeText(context, " Action is clicked" , Toast .LENGTH_SHORT ).show()
148+ }
141149 })
142150 }) {
143151 Text (" Snackbar with custom shape and colors" )
@@ -154,7 +162,9 @@ private fun SnackBarExample() {
154162 color = Color (0xffD32F2F ),
155163 fontWeight = FontWeight .Bold ,
156164 modifier = Modifier .clickable {
157- Toast .makeText(context, " Action is clicked" , Toast .LENGTH_SHORT ).show()
165+ if (! isInPreview) {
166+ Toast .makeText(context, " Action is clicked" , Toast .LENGTH_SHORT ).show()
167+ }
158168 })
159169 }) {
160170 Text (" Snackbar with custom shape and colors" )
0 commit comments