{"id":30752547,"url":"https://github.com/moinsen-dev/fix_flutter_deprecations","last_synced_at":"2025-10-20T06:24:35.534Z","repository":{"id":307798671,"uuid":"1030715870","full_name":"moinsen-dev/fix_flutter_deprecations","owner":"moinsen-dev","description":"A powerful and extensible Dart command-line tool that automatically fixes Flutter deprecations in your codebase. ","archived":false,"fork":false,"pushed_at":"2025-08-02T10:24:02.000Z","size":3192,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"develop","last_synced_at":"2025-08-02T10:31:43.505Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/moinsen-dev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-02T06:59:17.000Z","updated_at":"2025-08-02T10:24:05.000Z","dependencies_parsed_at":"2025-08-02T10:41:59.762Z","dependency_job_id":null,"html_url":"https://github.com/moinsen-dev/fix_flutter_deprecations","commit_stats":null,"previous_names":["moinsen-dev/fix_flutter_deprecations"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/moinsen-dev/fix_flutter_deprecations","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moinsen-dev%2Ffix_flutter_deprecations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moinsen-dev%2Ffix_flutter_deprecations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moinsen-dev%2Ffix_flutter_deprecations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moinsen-dev%2Ffix_flutter_deprecations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moinsen-dev","download_url":"https://codeload.github.com/moinsen-dev/fix_flutter_deprecations/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moinsen-dev%2Ffix_flutter_deprecations/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273574155,"owners_count":25129883,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-04T02:00:08.968Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-09-04T08:09:56.404Z","updated_at":"2025-10-20T06:24:35.418Z","avatar_url":"https://github.com/moinsen-dev.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fix Flutter Deprecations\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/moinsen-dev/fix_flutter_deprecations/develop/images/fix_deprecations_logo.png\" alt=\"Fix Flutter Deprecations Logo\" width=\"200\"/\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/moinsen-dev/fix_flutter_deprecations/actions\"\u003e\u003cimg src=\"https://github.com/moinsen-dev/fix_flutter_deprecations/actions/workflows/main.yaml/badge.svg\" alt=\"ci\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/moinsen-dev/fix_flutter_deprecations\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/moinsen-dev/fix_flutter_deprecations/develop/coverage_badge.svg\" alt=\"coverage\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://pub.dev/packages/very_good_analysis\"\u003e\u003cimg src=\"https://img.shields.io/badge/style-very_good_analysis-B22C89.svg\" alt=\"style: very good analysis\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://opensource.org/licenses/MIT\"\u003e\u003cimg src=\"https://img.shields.io/badge/license-MIT-purple.svg\" alt=\"License: MIT\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nA powerful and extensible Dart command-line tool that automatically fixes Flutter deprecations in your codebase. As Flutter evolves, APIs get deprecated and replaced with new ones. This tool helps you migrate your codebase efficiently by automatically applying common deprecation fixes.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/moinsen-dev/fix_flutter_deprecations/develop/images/fix_deprecations_wallpaper.png\" alt=\"Fix Flutter Deprecations in action\" width=\"800\"/\u003e\n\u003c/p\u003e\n\n## Features ✨\n\n- **Automatic Deprecation Fixes**: Automatically updates deprecated Flutter APIs to their modern equivalents\n- **Intelligent Code Transformation**: Smart handling of complex widget migrations like WillPopScope → PopScope\n- **Lint Rule Fixes**: Automatically resolves common linting issues like `use_build_context_synchronously`\n- **Extensible Architecture**: Easily add new deprecation rules as Flutter evolves\n- **Safe Operation**: Dry-run mode to preview changes before applying them\n- **Selective Fixes**: Apply specific deprecation fixes or all at once (6+ rules available)\n- **Progress Tracking**: Clear feedback on what's being changed\n- **Backup Support**: Optional backup creation before making changes\n\n## Currently Supported Deprecations\n\n| Rule | Deprecated API | Replacement | Flutter Version |\n|------|----------------|-------------|-----------------|\n| `withOpacity` | `.withOpacity(value)` | `.withValues(alpha: value)` | 3.27+ |\n| `surfaceContainerHighest` | `surfaceVariant` | `surfaceContainerHighest` | Material 3 |\n| `onSurface` | `onSurfaceVariant` | `onSurface` | Material 3 |\n| `willPopScope` | `WillPopScope` | `PopScope` | 3.12+ |\n| `multipleUnderscores` | Multiple underscores (`__identifier`) | Single underscore (`_identifier`) | Linting |\n| `buildContextAsync` | Unsafe BuildContext after async | Added mounted checks | Linting |\n\n### Detailed Rule Descriptions\n\n#### 🎨 **Flutter Widget Deprecations**\n- **`willPopScope`**: Converts deprecated `WillPopScope` to `PopScope` with intelligent callback transformation\n  - Simple boolean returns → `canPop` property\n  - Complex logic → `onPopInvoked` callbacks with proper navigation handling\n\n#### 🔧 **Linting Rule Fixes**\n- **`multipleUnderscores`**: Fixes \"unnecessary use of multiple underscores\" warnings\n  - Preserves generated code patterns and test mocks\n  - Converts `__identifier` to `_identifier` where appropriate\n\n- **`buildContextAsync`**: Fixes `use_build_context_synchronously` warnings  \n  - Detects BuildContext usage after async operations\n  - Adds `if (mounted)` checks for StatefulWidget\n  - Adds `if (context.mounted)` checks for other contexts\n  - Supports Navigator, showDialog, ScaffoldMessenger, Theme, and MediaQuery operations\n\n## Installation 📦\n\n### Global Installation\n\n```sh\ndart pub global activate fix_flutter_deprecations\n```\n\n### Local Development\n\n```sh\ndart pub global activate --source=path .\n```\n\n## Usage 🚀\n\n### Fix all deprecations in your project\n\n```sh\nfix_deprecations\n```\n\n### Preview changes without applying them (dry run)\n\n```sh\nfix_deprecations --dry-run\n```\n\n### Apply specific deprecation fixes\n\n```sh\nfix_deprecations --rules withOpacity,willPopScope,buildContextAsync\n```\n\n### Fix a specific file or directory\n\n```sh\nfix_deprecations lib/src/widgets/\nfix_deprecations lib/main.dart\n```\n\n### Create backups before fixing\n\n```sh\nfix_deprecations --backup\n```\n\n### List all available deprecation rules\n\n```sh\nfix_deprecations --list-rules\n```\n\n## Command Reference\n\n```sh\n# Fix all deprecations in current directory\nfix_deprecations\n\n# Fix with specific options\nfix_deprecations --dry-run --verbose\nfix_deprecations --rules withOpacity,willPopScope --backup lib/\n\n# List available deprecation rules\nfix_deprecations --list-rules\n\n# Show version\nfix_deprecations --version\n\n# Show help\nfix_deprecations --help\n```\n\n## Examples 💡\n\n### WillPopScope to PopScope Migration\n\n**Before:**\n```dart\nWillPopScope(\n  onWillPop: () async {\n    return await showDialog(...);\n  },\n  child: Scaffold(...),\n)\n```\n\n**After:**\n```dart\nPopScope(\n  canPop: false,\n  onPopInvoked: (bool didPop) async {\n    if (didPop) return;\n    final NavigatorState navigator = Navigator.of(context);\n    final bool shouldPop = await showDialog(...);\n    if (shouldPop) navigator.pop();\n  },\n  child: Scaffold(...),\n)\n```\n\n### BuildContext Async Safety\n\n**Before:**\n```dart\nFuture\u003cvoid\u003e _handleSubmit() async {\n  await _submitForm();\n  Navigator.of(context).pop(); // ⚠️ use_build_context_synchronously\n}\n```\n\n**After:**\n```dart\nFuture\u003cvoid\u003e _handleSubmit() async {\n  await _submitForm();\n  if (mounted) {\n    Navigator.of(context).pop(); // ✅ Safe to use\n  }\n}\n```\n\n### Multiple Underscores Fix\n\n**Before:**\n```dart\nclass MyClass {\n  String __privateField; // ⚠️ unnecessary multiple underscores\n}\n```\n\n**After:**\n```dart\nclass MyClass {\n  String _privateField; // ✅ Single underscore\n}\n```\n\n## Running Tests with coverage 🧪\n\nTo run all unit tests use the following command:\n\n```sh\n$ dart pub global activate coverage 1.2.0\n$ dart test --coverage=coverage\n$ dart pub global run coverage:format_coverage --lcov --in=coverage --out=coverage/lcov.info\n```\n\nTo view the generated coverage report you can use [lcov](https://github.com/linux-test-project/lcov)\n.\n\n```sh\n# Generate Coverage Report\n$ genhtml coverage/lcov.info -o coverage/\n\n# Open Coverage Report\n$ open coverage/index.html\n```\n\n## Adding New Deprecation Rules 🔧\n\nThe tool is designed to be easily extensible. To add a new deprecation rule:\n\n1. Create a new rule class in `lib/src/rules/`\n2. Implement the `DeprecationRule` interface\n3. Register the rule in the rule registry\n\nExample:\n```dart\nclass MyDeprecationRule extends DeprecationRule {\n  @override\n  String get name =\u003e 'myDeprecation';\n  \n  @override\n  String get description =\u003e 'Fixes MyOldAPI to MyNewAPI';\n  \n  @override\n  String apply(String content) {\n    // Implementation here\n  }\n}\n```\n\n## Architecture 🏗️\n\nThe project follows a clean, extensible architecture:\n\n- **Commands**: CLI commands for different operations (fix, list, etc.)\n- **Rules**: Individual deprecation fix implementations\n- **Processors**: File processing and transformation logic\n- **Utils**: Shared utilities for file operations, logging, etc.\n\n## Contributing 🤝\n\nContributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.\n\n### Adding a new deprecation fix:\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/new-deprecation-fix`)\n3. Add your deprecation rule with tests\n4. Ensure all tests pass and code follows Very Good Analysis standards\n5. Commit your changes (`git commit -m 'Add new deprecation fix for XYZ'`)\n6. Push to the branch (`git push origin feature/new-deprecation-fix`)\n7. Open a Pull Request\n\n---\n\nBuilt with [Claude Code](https://claude.ai/code) by [Moinsen Development](https://moinsen.dev) © 2025  \nBootstrapped with 💙 by [Very Good CLI][very_good_cli_link]\n\n[very_good_cli_link]: https://github.com/VeryGoodOpenSource/very_good_cli","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoinsen-dev%2Ffix_flutter_deprecations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoinsen-dev%2Ffix_flutter_deprecations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoinsen-dev%2Ffix_flutter_deprecations/lists"}