When working with Flutter and Dart, you’ll notice several folders inside your project directory — lib/, android/, ios/, test/, and others. Among them, there is a special hidden folder named .dart_tool/.
At first glance, many developers wonder: What is this folder? Why is it hidden? Can I delete it? Should I edit its files?
The .dart_tool/ folder often looks mysterious, but it plays a critical role in how Flutter and Dart projects are managed and executed.
In this article, we’ll explore .dart_tool/ in great detail:
- Why the folder exists
- What files and subfolders it contains
- How it interacts with dependencies and tools
- Why you should never edit it manually
- What happens if you delete it
- Common misconceptions about it
- Best practices for handling it
By the end, you will clearly understand the purpose of .dart_tool/ and how it fits into the bigger picture of Flutter development.
Why Does .dart_tool/ Exist?
The .dart_tool/ folder is auto-generated by Dart and Flutter tooling. Whenever you create a new project, run flutter pub get, or build your application, Flutter automatically creates or updates this folder.
The primary purposes of .dart_tool/ are:
- Dependency Management
- Stores metadata about which packages your project depends on.
- Ensures your code knows exactly which version of a library it’s using.
- Build Information
- Keeps track of compiled artifacts, caches, and build-related data.
- Tool Configurations
- Contains information used internally by Dart and Flutter command-line tools.
- Project Consistency
- Guarantees that builds are reproducible and consistent across different environments.
In short, .dart_tool/ is like the brain of your Flutter project’s tooling system. Without it, the project wouldn’t know how to resolve dependencies, run builds, or execute commands properly.
Location of .dart_tool/
The .dart_tool/ folder lives at the root of your Flutter project. For example:
my_flutter_app/
├── android/
├── ios/
├── lib/
├── test/
├── pubspec.yaml
├── pubspec.lock
├── .dart_tool/
Because it starts with a dot (.), it is treated as a hidden folder on Unix-like systems (Linux, macOS). On Windows, it may still show up unless hidden file visibility is disabled.
What’s Inside .dart_tool/?
The contents of .dart_tool/ may vary depending on your project setup, Flutter version, and the packages you use. However, there are some common components you’ll always find.
Let’s go through them:
1. package_config.json
This is one of the most important files. It stores information about all the dependencies in your project, including:
- Which packages you are using
- Their versions
- File paths for the local copy of each package
Whenever you run import 'package:xyz/xyz.dart'; in Dart, the system looks up this file to know where the package files are located.
2. .dart_tool/package_config_subset
This is a subset file used for faster lookups during builds.
3. .dart_tool/flutter_build/
This directory is created when you build your app (flutter build). It contains intermediate build files, caches, and metadata about the build process.
4. .dart_tool/pub/
This folder stores data about the pub package manager, including:
- Package cache locations
- Checksums to verify package integrity
- Records of what has been downloaded and resolved
5. .dart_tool/versions/
Sometimes, Flutter stores information about specific versions of tools being used to ensure compatibility.
Why You Should NOT Edit .dart_tool/ Manually
A very important rule:
👉 Never manually edit files inside .dart_tool/.
Why? Because:
- These files are machine-generated, not meant for humans.
- Any changes you make will be overwritten the next time you run
flutter pub getorflutter build. - Incorrect edits can break your project by corrupting dependency metadata.
Think of .dart_tool/ as the operating system’s hidden files — necessary for smooth functioning but not meant for direct modification.
Can You Delete .dart_tool/?
Yes — but with caution.
If you delete the .dart_tool/ folder, your project won’t break permanently. However, the next time you run:
flutter pub getflutter runflutter build
Flutter will recreate the folder from scratch.
This is actually a common troubleshooting step. For example:
- If your project is failing to resolve dependencies.
- If you get weird caching issues.
- If
flutter pub getseems stuck.
In such cases, deleting .dart_tool/ and then re-running flutter pub get can refresh everything and fix the issue.
Relationship Between .dart_tool/, pubspec.yaml, and pubspec.lock
To fully understand .dart_tool/, you need to see how it works with other key files:
pubspec.yaml→ The manifest where you declare dependencies (e.g.,http: ^1.0.0).pubspec.lock→ The lockfile that records the exact versions used (e.g.,http: 1.0.2)..dart_tool/package_config.json→ Maps each dependency to its physical location on disk.
Here’s how it works step by step:
- You declare dependencies in
pubspec.yaml. - You run
flutter pub get. - Flutter resolves compatible versions and writes them to
pubspec.lock. - Flutter stores metadata and paths in
.dart_tool/.
This ensures that your app can reliably import and use dependencies across machines and builds.
Why is .dart_tool/ Hidden?
The folder is hidden because:
- It contains internal system files not meant for direct editing.
- Developers shouldn’t need to worry about its contents.
- Keeping it hidden keeps your project directory cleaner and less confusing.
You can think of it like a .git/ folder in Git repositories — essential for functionality, but not meant to be touched directly.
Should You Commit .dart_tool/ to Git?
The answer is: No.
.dart_tool/ should not be included in version control. It is already listed in the default .gitignore file when you create a Flutter project.
Why?
- It is auto-generated.
- It can differ from machine to machine.
- Committing it would only create unnecessary conflicts.
Instead, commit:
pubspec.yaml(declared dependencies)pubspec.lock(exact versions)
This way, any developer cloning your project can simply run flutter pub get to regenerate .dart_tool/.
When Do You Interact with .dart_tool/?
Most of the time, you won’t. Flutter handles everything for you.
However, you may need to interact with it indirectly when:
- Troubleshooting Dependency Errors
- If you get errors like “Package not found” or “Dependency conflict,” deleting
.dart_tool/often helps.
- If you get errors like “Package not found” or “Dependency conflict,” deleting
- Clearing Cache
- When packages get corrupted, clearing
.dart_tool/resets your environment.
- When packages get corrupted, clearing
- Understanding Dependency Resolution
- Advanced developers may inspect
package_config.jsonto debug version issues.
- Advanced developers may inspect
But 99% of the time, you simply let it exist in the background.
Common Misconceptions About .dart_tool/
- “It’s bloat, I can delete it permanently.”
- Wrong. It will be recreated automatically.
- “I should edit it to fix dependency issues.”
- Wrong. Dependency fixes must be done in
pubspec.yaml, not here.
- Wrong. Dependency fixes must be done in
- “It’s the same as
.idea/or.vscode/.”- Wrong.
.dart_tool/is part of the Flutter/Dart ecosystem, while.idea/or.vscode/are IDE-related.
- Wrong.
- “It doesn’t matter if I commit it to Git.”
- Wrong. It will cause unnecessary clutter and conflicts.
Best Practices for Handling .dart_tool/
- Don’t touch it manually — let Flutter handle it.
- Exclude it from version control — keep your repository clean.
- Delete it only when necessary — as a troubleshooting step.
- Rely on
pubspec.yaml— make all dependency changes there. - Run
flutter pub get— to regenerate.dart_tool/when needed.
Real-World Example
Imagine you’re building a chat application using Flutter.
- You declare dependencies like
firebase_auth,cloud_firestore, andproviderinpubspec.yaml. - You run
flutter pub get. - Flutter downloads those packages and records versions in
pubspec.lock. - Then it creates
.dart_tool/package_config.jsonto map those packages to your local system.
Now, when you write:
import 'package:cloud_firestore/cloud_firestore.dart';
Flutter knows exactly where to find the cloud_firestore files, thanks to .dart_tool/.
If .dart_tool/ were missing or corrupted, you’d get “Package not found” errors.
Leave a Reply