question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Override suggestion not offered using quickfix if @override option deleted from build

See original GitHub issue

If 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:open
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
DanTupcommented, Sep 3, 2019

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:

class Base {
  void initState() {}
  void build() => '';
}

class Foo extends Base {
  init // works fine here
  
  void build() => '';
}

But if I replace both voids with String then it no longer works.

class Base {
  void initState() {}
  String build() => '';
}

class Foo extends Base {
  init // works fine here
  
  String build() => '';
}

The difference in the AST seems to be that when the return type on the following method is void, then the completion target is init; as a FieldDeclaration, but when the return type is String then it gets init String; as a FieldDeclaration and this code fails because init is in the type field, and this code looks for a null type.

@bwilkerson is it correct that the AST differs in this way between having void vs String? It might be tricky to handle this in the override contributor because the AST seems a bit misleading (it contains a FieldDeclaration for init String when String is actually the return type of the following method.

0reactions
DanTupcommented, Sep 3, 2019

@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!).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found