简体   繁体   English

单击布局功能时如何显示全屏对话框或导航到其他屏幕?

[英]How can I show full screen dialog or navigate to other screen when I click a Layout function?

  1. I have AppBarNavGraph and RootNavGraph.我有 AppBarNavGraph 和 RootNavGraph。
  2. I'd like to know two methods, Full Screen Dialog and also Navigating to a new Screen.我想知道两种方法,全屏对话框和导航到新屏幕。

What I am trying to is..我想做的是..

Column(
        modifier = Modifier
            .width(97.dp)
            .clickable {
                Dialog(onDismissResult = { /*TODO*/ }) {

                }
            }
        ,
        horizontalAlignment = Alignment.CenterHorizontally

But in clickable, composable function is not callable.但是在可点击的情况下,可组合的功能是不可调用的。

So, What I tried is using this,所以,我尝试的是使用这个,

    val isClicked = remember { mutableStateOf(false) }

    Column(
        modifier = Modifier
            .width(97.dp)
            .clickable {
                isClicked.value = !isClicked.value
            },
        horizontalAlignment = Alignment.CenterHorizontally
    ) 

    if(isClicked.value){
        // show full screen dialog or navigate to some screen.
    }

Here are two problems.这里有两个问题。

  1. I tried with Dialog function.我尝试了 Dialog 功能。
Dialog(
    onDismissResult: () -> Unit,
    properties: DialogProperties = DialogProperties(),
    content: @Composable () -> Unit
)

but, this doesn't show full screen but just next item.但是,这不会显示全屏,而是显示下一个项目。 (it's in GridLayout and when I click an item, the dialog needs to shows up to add the item.) (它在 GridLayout 中,当我单击一个项目时,需要显示对话框以添加该项目。)

  1. For navigation, I tried, varies ways, but I haven't found any clear solutions...对于导航,我尝试过多种方式,但我还没有找到任何明确的解决方案......

Could you please help me out?你能帮帮我吗? or any advices?或任何建议?

This should do the trick for a simple full screen popup这应该可以解决简单的全屏弹出窗口


 var showPopup by remember { mutableStateOf(false) }

    Box(Modifier
        .background(Color.Blue)
        .fillMaxSize()) {
        Button(onClick = { showPopup = true }) {
            Text("Show popup")
        }
    }

    if (showPopup) {
        Popup(
            onDismissRequest = { showPopup = false }
        ) {
            Box(Modifier
                .background(Color.Red)
                .fillMaxSize()) {
                Button(onClick = { showPopup = false },
                    modifier = Modifier.align(Alignment.Center)) {
                    Text("Hide popup")
                }
            }
        }
    }

Though if you want proper navigation you should probably use this虽然如果你想要正确的导航,你应该使用这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我使用根名称导航时,如何在Flutter中创建全屏对话框? - How to create full screen dialog in flutter when I am using root names to Navigate? 单击其他屏幕元素时,如何防止此Android列表视图中的图像移动? - How can I prevent images in this Android listview from shifting around when I click on other screen elements? 对话框全屏布局问题 - Dialog full screen layout issue 使用 DialogFragment 和导航库时将对话框显示为全屏或对话框 - Show dialog as full screen or as dialog when using DialogFragment and Navigation Library 如何设置保持屏幕开启和全屏标志? - How I can set keep screen on and full screen flag? 全屏显示图像,然后对话框 - Show image full screen then dialog 如何使启动画面变为全屏? - How can I make splash screen to full screen? 如何在imageView点击时全屏显示imageView? - How to show imageView full screen on imageView click? 当我单击屏幕中的任何位置时,我想隐藏片段布局 - i want to hide fragment layout when click any place in screen 我怎样才能让这些组件导航到另一个屏幕做出反应? - How can I make these components navigate to another screen in react?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM