Override suggestion not offered using quickfix if @override option deleted from build
See original GitHub issueIf you type ‘ini’ above the @override
statement below you get the initState suggestion. If the override statement is deleted then you don’t get the suggestion. I heard Filip on the Boring Show say the @override
element isn’t necessary. Should we always specify @override
on our overridden funcions or is there another way of getting the suggestion to work when @override
has been removed?
class _TestWidgetState extends State<TestWidget> {
@override
Widget build(BuildContext context) => Text("blah");
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Quick-fixes for code issues | JetBrains Rider Documentation
It is as simple as pressing Alt+Enter at a highlighted code issue and choosing the appropriate way to fix the problem or improve...
Read more >Flutter Fix
This shows a list of all actions, including refactors. Put the caret in the code with the error and press the shortcut (Command+....
Read more >Gerrit error when Change-Id in commit messages are missing
If no, use git rebase -i to reword the commit messages and add proper Change-Ids (usually this is a SHA1 of the first...
Read more >Tools attributes reference | Android Studio
When you build your app, the build tools remove these attributes so there is no effect on your APK size or runtime behavior....
Read more >Suggest changes - GitLab Docs
A code change suggestion displayed, with the option to remove that suggestion from its batch. Having added all the suggestions to your liking,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hmmm, it seems when I tested this, I ended up debugging a different issue 😃
The issue I found was because of a missing return type on my second method, so it though what I was typing was the return type (and therefore didn’t show override completions). However, re-testing it with a return type I see strange behaviour:
But if I replace both
void
s withString
then it no longer works.The difference in the AST seems to be that when the return type on the following method is
void
, then the completion target isinit;
as aFieldDeclaration
, but when the return type isString
then it getsinit String;
as aFieldDeclaration
and this code fails becauseinit
is in thetype
field, and this code looks for a null type.@bwilkerson is it correct that the AST differs in this way between having
void
vsString
? It might be tricky to handle this in the override contributor because the AST seems a bit misleading (it contains a FieldDeclaration forinit String
whenString
is actually the return type of the following method.@bwilkerson thanks for the details, all makes sense!
@twistedinferno to answer your original question - this is probably a reason that having the annotations works out better (there’s a lint you can enable if you want to enforce this) - though it won’t help if you’re trying to add an override immediately before a non-override method.
If the parser is improved to handle this differently in the future it will just start working as you’d like without any changes here, so I don’t think there’s anything to do in the VS Code extension (nor can I think of any reasonable workarounds in the meantime I’m afraid!).