How do you solve the "closing brackets syndrome" in Flutter/Dart? - flutter

I think, one of the most annoying problems when coding Flutter is when you become confused/out of sync of those closing brackets.
To me, it happens often that I add a new parent widget or insert a code snipped and then the closing curly/square/round brackets do not match, or semicolon/colon is missing... Of course, it is solvable: go to each bracket and the tooling will show you the counter-bracket and maybe you detect the discrepancy fast...or not. As you can see in the snipped, the tooling helps a bit by showing the corresponding class/widget. But to get it into sync, it always takes ages....
Do you have any best practises or hints/suggestions how to quickly adjust the brackets? What is your experience?
Thanks!

In VsCode you have some very usefull shortcuts to :
remove a widget
surround an existing widget with a new one
and more
And it handles the adding/removing of brackets :
Gif took from this answer

Quick Tip!
I use IDE integrated features to avoid mistakes and it saves my time as well. Check below example. Don't try to wrap manually.
I found this article myself quite useful when it comes to avoid bracketing mistakes and fasten developments.

There are some suggestions for you
1 - Switch to vscode its lighter, faster and you can use its intelli sense or what we call code action to add widgets and remove wherever you want in your flutter code. By doing this it will automatically take care of brackets and stuff.
2- Use flutter snippets extension there are a lot of them available on vscode at-least, not sure about android studio but the extension it will auto generate a boilerplate template for you along with the brackets
3- You can go to vscode or your android studio's flutter extension settings and customize it, there are options for auto formatting and importing as well.
4- (Optional) If you have github co-pilot then it auto suggests you about the brackets and code but not always accurate and also co-pilot is not officially available for all but its way too good to have.

You can seperate your code to functions or even better create your own Widgets. Let's
say you have to display bunch of movies as gird of cards on a main page. Instead nesting them inside giant Scaffold you can create
ListOfMovies widget using GridView which consumes List<Movie>
CardMovie widget which consumes single Movie object
Here is how I seperated them on my own project. This is not the perfect but may be helpful
Edit.
Here is another minor tip: On JetBrains IDEs you can jump to other end of brackets or curly brackets using Ctrl+Shift+M command

Related

Is there a way I can get a code block always visible while scrolling in VS Code?

That's all, sometimes I miss I could do that while working on different parts of a kinda long script or whatever... So I think it'd be nice if, as we can do in a spread sheet by fixing a row for example, we could quickly define certain part of the code we want always visible and then can scroll to any other part of the script while still being able to see such "fixed" lines of code as a reference, copy, etc.
It seemed to me that it could be an already existing feature, but I've been not able to find anything... not even an extension, but maybe someone here knows? Well, I hope it makes sense and thanks in advance!
How about spliting the editor?
Hard to guess for how large "sticky" portion of code you are actually aiming, but if it is just, say, function "signature line" or nesting header in general, you may try experimental "Editor sticky scroll" (editor.experimental.stickyScroll.enabled) feature that was just released in VSC v1.70:
https://code.visualstudio.com/updates/v1_70#_editor-sticky-scroll

Hide VSCode snippets in suggestion list when no code is written?

In VSCode there is a setting for having snippets first in the list of suggestions ("editor.snippetSuggestions": "top",). This is great, as you might want a snippet to take precedence over other intellisense items when it matches what you've written.
However, the snippets will also be ordered at the top when you display suggestions without writing anything. I often show suggestions inside classes to see what properties/methods I have available, but in those cases I have to scroll through my entire list of snippets before the properties/methods show up. Is there any way to turn off snippet suggestions when you have not written anything?
Example image of the suggestions showing above halfway down in the suggestion list:
This is not an option as of yet, and a feature request for this funtionality has been added. https://github.com/microsoft/vscode/issues/147357
In the meantime, a workaround is to hide snippets from completions and use the explicit > Insert Snippet command instead. (Copied from the issue response)

How to prevent Visual Studio Code Flutter/Dart Editor from formatting new line/wrapping code?

I recently started working on Flutter/Dart, I like the flutter autoformatting on-save, but one thing might or might not be related is the code wrapping for long code even if code is still fitting my 4k editor window.
Is there a way to prevent new line but keep the comma auto format?
Thanks
Follow the instructions below:
Open Settings.
Expand Extensions and click Dart & Flutter on the left.
Find Dart: Line Length.
Change it to the value you want.

Is there a way to disable 'clips' in VS Code?

The clips feature has been around for some versions in VS Code. It automatically tracks what code I wrote (or copied?) and then offers these clips on a popup when starting a similar statement (e.g. a return statement):
However, this feature drives me nuts. There has been no single circumstance where I benefited from it (why would a seasoned programmer repeat parts of his code? Code-reuse, anyone?). However, if I'm typing fast and I'm not careful, I accidentally select it and the whole clip gets pasted.
Is there a way to disable this feature in VS Code? I neither found any corresponding settings in the official docs nor did any search engine point me in the correct direction.
Thanks in advance for your help!

How to completely hide comments in eclipse?

I'm not sure if this is a good place for this question, but I did see a similar question posted here on overflow.
I'm just getting started with Eclipse as an IDE and having difficulty finding a comments toggle. I'd like to completely hide them sometimes. I've seen suggestions that would allow me to collapse entire comment blocks to a single line, but I'd want to hide ALL comments (single lines, blocks, etc) like in visual studio as a comparison. The goal is to gain the screen space to see more actual code simultaneously.
Anyone know of a way, plugin or otherwise?
Thanks!
This might be a bad way of doing it but you could set the syntax highlight for comments to be the same as your background color.