Home > other >  How to group or block a line of codes
How to group or block a line of codes

Time:12-28

I'm working with Flutter and Android Studio. I am trying to block *ahem* Group some line of codes so that I can just hide it by clicking the plus icon on the left hand side.

How to group a line of codes as a single block in Android Studio and/or Flutter?

CodePudding user response:

If I am not getting you wrong , you are talking about The Code Folding shortcuts in Android Studio. They allow us to fold Code Blocks & Region Blocks so we can have more fine grained control over what code we are looking at in any given moment. Have you checked these from official page:

Collapse/expand current code block  Control minus or Control plus   Command minus or Command plus

Collapse/expand all code blocks Control Shift minus or Control Shift plus   Command Shift minus or Command Shift plus

For creating a region you can do this simply :

//start region  method
    //your work here
//endregion

to open this

control shift  (plus  )

to close the region:

control shift  (minus -)

https://developer.android.com/studio/intro/keyboard-shortcuts

or Check this : https://proandroiddev.com/code-folding-in-android-studio-5d046517dadc

CodePudding user response:

You can write the block as a new method, then call it whenever you want, and you can set any conditions during calling or you can use Visibility widget to work with visibility of your block

 .....
if(!hidden)
 myBlock();
.....
  • Related