11

I want to hide auto generated dart files like .g.dart, .freezed.dart from vs code project. How to do that?

Newaj
  • 3,992
  • 4
  • 32
  • 50
  • 1
    Does this answer your question? [How do I hide certain files from the sidebar in Visual Studio Code?](https://stackoverflow.com/questions/30140112/how-do-i-hide-certain-files-from-the-sidebar-in-visual-studio-code) – Abion47 Sep 03 '20 at 04:16
  • Are the generated filenames somehow related to certain `.dart` filenames? – Mark Sep 03 '20 at 22:01
  • Yes, for example `file_name.freezed.dart`. – Newaj Sep 04 '20 at 03:43
  • @Abion47 probably, but what should it be for a file name like : `file_name.freezed.dart`? Here I want to hide all the files having `freezed.dart`. – Newaj Sep 04 '20 at 03:45
  • @Newaj Read the linked answer. – Abion47 Sep 04 '20 at 16:00

4 Answers4

19

create a folder

.vscode

create

settings.json

put this:

{
  "files.exclude": {
    "**/*.freezed.dart": true,
    "**/*.g.dart": true
  },
}

this make local configuration in your project.

Lucas Breitembach
  • 1,515
  • 11
  • 15
11

In v1.67 you can create an entry in the

Explorer > File Nesting: Patterns setting like so:

*.dart $(capture).g.dart, $(capture).freezed.dart

file nesting in dart demo

explorer.fileNesting.enabled: Controls whether file nesting is enabled
explorer.fileNesting.expand: Controls whether file nests show as expanded by default
explorer.fileNesting.patterns: Controls how files get nested


In addition the Explorer: Sort Order setting has a new option:

foldersNestsFiles: Files and folders are sorted by their names. Folders are displayed before files. Files with nested children are displayed before other files.

sortOrder.foldersNestsFiles

See also v1.67b Release Notes: File Nesting

Make sure you have Explorer > File Nesting: Enabled true

Mark
  • 143,421
  • 24
  • 428
  • 436
8

TL;DR

Type Ctrl/Cmd + Shift + p, choose Preferences: Open Settings (JSON) or Preferences: Open Workspace Settings (JSON) and add:

"files.exclude": {
    "**/*.freezed.dart": true,
    "**/*.g.dart": true
},

You can add more patterns if you like. Here you can find more information about the patterns.

More info

You can configure this in your workspace or user settings:

Open settings: Ctrl/Cmd + Shift + p and search for 'Preferences: Open Settings'. You can choose from 'Workspace Settings' or your 'User Settings', depending on if you want to exclude the files just in your current project (workspace) or for all projects. And you can choose if you want to use the UI tool or to modify the settings json file manually.

Using the UI tool:

Search for files.exclude and you can add patterns you want to hide in the project explorer. In your case add **/*.freezed.dart and **/*.g.dart, but you can exclude any pattern you like.

Editing the json file manually:

Type Ctrl/Cmd + Shift + p and search for 'Preferences: Open Settings (JSON)' or Preferences: Open Workspace Settings (JSON). Again, depending on if you want to exclude the files just in your current project (workspace) or for all projects.

Add this part to the json file:

"files.exclude": {
    "**/*.freezed.dart": true,
    "**/*.g.dart": true
},

Or add just the pattern lines, if files.exclude is already present in the settings.json file.

cumul
  • 864
  • 9
  • 21
2

"On Mac. Open VSCode, Type Shift+Command+P, Preferences: Configure, Language Specific Settings, Choose the Language (Dart), Then add to file "

"files.exclude": { "/.git": true, "/.svn": true, "/.hg": true, "/CVS": true, "/.DS_Store": true, "/*.g.dart":true, }

Save

Now, you don't see the *.g.dart files.

Carlos
  • 91
  • 1
  • 3