0

I'm using compose desktop 1.2.0 using Kotlin 1.7.20, When I use alert dialog I get only a small alert dialog that shrinks the text inside.

I've tried that minimal code:

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.*
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.singleWindowApplication

@OptIn(ExperimentalMaterialApi::class)
fun main() = singleWindowApplication {
    val text by remember { mutableStateOf("Hello, World!") }
    var alertDialog by remember { mutableStateOf(false) }
    MaterialTheme {
        Button(onClick = {
            alertDialog = true
        }) {
            Text(text)
        }
        if (alertDialog)
            AlertDialog(onDismissRequest = {
                alertDialog = false
            },
                title = { Text("About me") },
                text = {
                    Text("Blah Blah Blah Blah")
                },
                confirmButton = {
                    Column {
                        TabRowDefaults.Divider(thickness = 1.dp)
                        Button(modifier = Modifier.fillMaxWidth(),
                            onClick = { alertDialog = false }) {
                            Text("OK")
                        }
                    }
                }
            )
    }
}

I expect a larger alert that fits the content inside. I've tried that minimal code:

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.*
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.singleWindowApplication

@OptIn(ExperimentalMaterialApi::class)
fun main() = singleWindowApplication {
    val text by remember { mutableStateOf("Hello, World!") }
    var alertDialog by remember { mutableStateOf(false) }
    MaterialTheme {
        Button(onClick = {
            alertDialog = true
        }) {
            Text(text)
        }
        if (alertDialog)
            AlertDialog(onDismissRequest = {
                alertDialog = false
            },
                title = { Text("About me") },
                text = {
                    Text("Blah Blah Blah Blah")
                },
                confirmButton = {
                    Column {
                        TabRowDefaults.Divider(thickness = 1.dp)
                        Button(modifier = Modifier.fillMaxWidth(),
                            onClick = { alertDialog = false }) {
                            Text("OK")
                        }
                    }
                }
            )
    }
}

I expect a larger alert that fits the content inside.example

IdanB
  • 167
  • 1
  • 3
  • 13
  • Seems duplicate https://stackoverflow.com/questions/69160300/how-to-change-the-width-of-dialog-in-android-compose. Try use modifier instead. – androidStud Oct 31 '22 at 03:35

0 Answers0