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.

Refactoring - Move Widget/Class to New File

See original GitHub issue

I don’t know if this is VSCode feature request or specifically for dart/flutter, but is it possible to move a widget class (or any other class) to a new file? If I remember correctly Visual Studio have this refactoring option.

Say I have this my_widget.dart file.

class MyWidget extends StatelessWidget {
  const MyWidget({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: child,
    );
  }
}

class MyOtherWidget extends StatelessWidget {
  const MyOtherWidget({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: child,
    );
  }
}

I want to move MyOtherWidget to my_other_widget.dart (automatically created) and automatically import that file if my_widget.dart contains MyOtherWidget references. Sorry if this is a duplicate. Thank you.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:162
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

16reactions
tieorangecommented, Apr 14, 2022

Any updates? It would be useful during refactor of legacy code for us

14reactions
DanTupcommented, Jul 8, 2019

This requires support in the SDK’s analysis server before it can be supported here. There’s an open issue for it you can 👍 and subscribe to at https://github.com/dart-lang/sdk/issues/30310.

If it’s added to the server, then it could be exposed here in VS Code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flutter Refactoring move widgets to new files - Stack Overflow
I want to move its children to new files. I already have Widget TabContent1 and Widget TabContent2 in the same class, but how...
Read more >
Move Type to Another File refactoring - JetBrains Rider
Move a type to another file · Press Ctrl+R, O and then choose Move to Another File · Press Ctrl+Shift+R and then choose...
Read more >
How refactoring improve readability, maintainability and ...
3. Refactoring with a widget class · Open the any . · Place the cursor on the first widget and right-click, in my...
Read more >
Refactorings and Code Fixes
leadingNewlineToString.multi - Add leading new line everywhere in file; quickfix.add. ... moveTypeArgumentsToClass - Move type arguments to after class name ...
Read more >
Flutter Tutorial for Beginners #20 - Extracting Widgets - YouTube
Hey gang, in this Flutter tutorial I'll show you how you can extract widget trees into their own re-usable class widget.
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