Sure,
A quick fix example could be "Extract To Functional Widget" where you can execute it when cursor is over a Widget (very similar to "Extract Widget").
It should move the widget and its content into a new function like this, adding every params required:
@swidget
Widget functionName(BuildContext context, int value) {
return Text('$value');
}
And it should place the function name where there was the widget before.
Why I need params?
I can use them to customize the generated output:
- Instead of 'functionName', I can prompt the user for the name to insert or put 'functionName' as default if nothing is passed (and I have seen that is the current behavior with Extract Widget).
- I can also ask the user which decorator to write (@swidget, @hwidget, @hcwidget, @hwidget). However, I'm still thinking of putting it in my VS Code extension settings, where you can choose the default decorator to use and if set, skip the decorator request during the quick fix execution. In fact, I could take my VS Code extension settings and use them during this process to customize the output, such as "always add key param to the function" or "prefer arrow functions" (I know, these are trivial things).
As I said, there's no
OnWillExecuteCommand in VS Code, but there's onDidExecuteCommand: maybe I can do something after the command execution, however I don't think it's a great way to do it.