Doctor Command
The doctor
command checks the health of your Flutter project and identifies common issues. It can also fix some problems automatically. This command helps ensure your project follows best practices and is properly configured.
Usage
flutter_bunny doctor [options]
Options
-directory
orC
: Directory to check (default: ".")-project-only
: Only check project-specific issues, not Flutter SDK-fix
orf
: Attempt to fix issues automatically
Examples
Check Project Health
flutter_bunny doctor
This will check your Flutter project for common issues and the Flutter environment.
Check Project Only
flutter_bunny doctor --project-only
This will only check project-specific issues, skipping the Flutter SDK check.
Check and Fix Issues
flutter_bunny doctor --fix
This will check your project and attempt to automatically fix any identified issues.
Check a Specific Directory
flutter_bunny doctor --directory ./packages/my_package
This will check the specified directory for issues.
What Doctor Checks
The doctor
command checks for various issues, including:
Flutter Environment
- Flutter SDK installation and version
- Development tools (Android Studio, Xcode, etc.)
- Connected devices
- Dependencies and plugins
Project Structure
- Required files (
pubspec.yaml
, etc.) - Proper directory structure
- Configuration files (analysis_options.yaml, etc.)
- Test directory setup
Dependencies
- Up-to-date dependencies
- Pubspec.lock consistency
- Conflicting dependencies
Best Practices
- Gitignore configuration
- README and documentation
- License files
- Project organization
Fixing Issues
When run with the --fix
flag, the doctor command can automatically fix several issues:
- Generate missing configuration files
- Update outdated dependencies
- Create template files for tests
- Set up proper .gitignore
- Initialize missing directories
Example Output
Running Flutter doctor...
Flutter environment looks good!
Flutter Doctor Output:
[✓] Flutter (Channel stable, 3.10.5, on macOS 13.4.1)
[✓] Android toolchain - develop for Android devices
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.1)
[✓] VS Code (version 1.78.2)
[✓] Connected device (2 available)
[✓] HTTP Host Availability
Checking project health...
Found 3 issues with your project
Project Health Check Results:
1. Missing analysis_options.yaml
No analysis_options.yaml file found. This file helps maintain code quality.
This issue can be fixed automatically with --fix
Recommendations:
- Create an analysis_options.yaml file with appropriate lints
- Consider using package:lints/recommended.yaml as a base
2. Empty test directory
The test directory exists but contains no tests.
Recommendations:
- Add unit, widget, and integration tests to your project
- Run "flutter test" to execute your tests
3. Minimal lib directory structure
The lib directory has minimal structure. Consider organizing your code better.
Recommendations:
- Create subdirectories for different parts of your app (widgets, screens, models, etc.)
- Separate business logic from UI code
Best Practices
- Run doctor regularly: Make it part of your development workflow
- Fix critical issues first: Focus on errors before warnings
- Use the
-fix
option: Let the tool fix common issues automatically - Follow recommendations: Implement suggested changes for best practices
- Run before releases: Ensure your project is healthy before distribution