Repository navigation
Guides agent away from deprecated material and cupertino libraries #271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chunhtai
wants to merge
1
commit into
main
Choose a base branch
from
material_ui
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| --- | ||
| description: Use standalone material_ui and cupertino_ui packages for Material Design and Cupertino APIs in Flutter code instead of legacy SDK imports. | ||
| trigger: glob | ||
| globs: "**/*.dart" | ||
| --- | ||
|
|
||
| # Use Standalone Material and Cupertino Packages | ||
|
|
||
| Material Design and Cupertino libraries live in the standalone `material_ui` and `cupertino_ui` packages, separate from the core `flutter` SDK package. | ||
|
|
||
| When writing or editing Flutter `.dart` code: | ||
|
|
||
| 1. **Material Design (`material_ui`)**: | ||
| - Add `material_ui` to `pubspec.yaml` (`flutter pub add material_ui`) if not already present. | ||
| - Import `package:material_ui/material_ui.dart`. Do not import `package:flutter/material.dart`. | ||
|
|
||
| 2. **Cupertino (`cupertino_ui`)**: | ||
| - Add `cupertino_ui` to `pubspec.yaml` (`flutter pub add cupertino_ui`) if not already present. | ||
| - Import `package:cupertino_ui/cupertino_ui.dart`. Do not import `package:flutter/cupertino.dart`. | ||
|
|
||
| 3. **Core Widgets**: | ||
| - When a file only uses design-agnostic framework APIs (such as `Widget`, `StatelessWidget`, `BuildContext`, `Key`, or layout primitives), import `package:flutter/widgets.dart` instead of adding a design package import. | ||
|
|
||
| 4. **Localization Delegates**: | ||
| - Import `GlobalMaterialLocalizations` from `package:material_ui/material_ui.dart` (typically via `GlobalMaterialLocalizations.delegates`) and `GlobalCupertinoLocalizations` from `package:cupertino_ui/cupertino_ui.dart` (typically via `GlobalCupertinoLocalizations.delegates`). | ||
| - Do not import `GlobalMaterialLocalizations` or `GlobalCupertinoLocalizations` from `package:flutter_localizations/flutter_localizations.dart`. Use `flutter_localizations` only for `GlobalWidgetsLocalizations` and SDK localization tooling. | ||
|
|
||
| 5. **Scope and Older SDK Projects**: | ||
| - Skip this rule for pure Dart packages without Flutter UI. | ||
| - If making targeted edits in a project pinned to an older Flutter SDK that still uses `package:flutter/material.dart` or `package:flutter/cupertino.dart`, avoid mixing types from those legacy SDK libraries with `material_ui` or `cupertino_ui` types in the same widget subtree unless migrating the project. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| --- | ||
| description: Use standalone material_ui and cupertino_ui packages for Material Design and Cupertino APIs in Flutter code instead of legacy SDK imports. | ||
| globs: "**/*.dart" | ||
| alwaysApply: false | ||
| --- | ||
|
|
||
| # Use Standalone Material and Cupertino Packages | ||
|
|
||
| Material Design and Cupertino libraries live in the standalone `material_ui` and `cupertino_ui` packages, separate from the core `flutter` SDK package. | ||
|
|
||
| When writing or editing Flutter `.dart` code: | ||
|
|
||
| 1. **Material Design (`material_ui`)**: | ||
| - Add `material_ui` to `pubspec.yaml` (`flutter pub add material_ui`) if not already present. | ||
| - Import `package:material_ui/material_ui.dart`. Do not import `package:flutter/material.dart`. | ||
|
|
||
| 2. **Cupertino (`cupertino_ui`)**: | ||
| - Add `cupertino_ui` to `pubspec.yaml` (`flutter pub add cupertino_ui`) if not already present. | ||
| - Import `package:cupertino_ui/cupertino_ui.dart`. Do not import `package:flutter/cupertino.dart`. | ||
|
|
||
| 3. **Core Widgets**: | ||
| - When a file only uses design-agnostic framework APIs (such as `Widget`, `StatelessWidget`, `BuildContext`, `Key`, or layout primitives), import `package:flutter/widgets.dart` instead of adding a design package import. | ||
|
|
||
| 4. **Localization Delegates**: | ||
| - Import `GlobalMaterialLocalizations` from `package:material_ui/material_ui.dart` (typically via `GlobalMaterialLocalizations.delegates`) and `GlobalCupertinoLocalizations` from `package:cupertino_ui/cupertino_ui.dart` (typically via `GlobalCupertinoLocalizations.delegates`). | ||
| - Do not import `GlobalMaterialLocalizations` or `GlobalCupertinoLocalizations` from `package:flutter_localizations/flutter_localizations.dart`. Use `flutter_localizations` only for `GlobalWidgetsLocalizations` and SDK localization tooling. | ||
|
|
||
| 5. **Scope and Older SDK Projects**: | ||
| - Skip this rule for pure Dart packages without Flutter UI. | ||
| - If making targeted edits in a project pinned to an older Flutter SDK that still uses `package:flutter/material.dart` or `package:flutter/cupertino.dart`, avoid mixing types from those legacy SDK libraries with `material_ui` or `cupertino_ui` types in the same widget subtree unless migrating the project. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,19 +61,17 @@ synthetic-package: true | |
| ``` | ||
|
|
||
| ### 4. Configure the App Entry Point | ||
| Import the generated localizations and the `flutter_localizations` library in your `main.dart`. Inject the delegates and supported locales into your `MaterialApp` or `CupertinoApp`. | ||
| Import the generated localizations alongside `package:material_ui/material_ui.dart` (or `package:cupertino_ui/cupertino_ui.dart` for a `CupertinoApp`) in your `main.dart`. Pass `GlobalMaterialLocalizations.delegates` (which bundles the Material, Cupertino, and Widgets delegates) or `GlobalCupertinoLocalizations.delegates` into `localizationsDelegates` rather than importing Material or Cupertino delegates from `flutter_localizations`. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @QuncCccccc can you help me check if changes to this skill sounds good to you |
||
|
|
||
| ```dart | ||
| import 'package:flutter_localizations/flutter_localizations.dart'; | ||
| import 'package:flutter_gen/gen_l10n/app_localizations.dart'; // Adjust path if synthetic-package is false | ||
| import 'package:material_ui/material_ui.dart'; | ||
|
|
||
| // ... inside build method | ||
| return MaterialApp( | ||
| localizationsDelegates: const [ | ||
| AppLocalizations.delegate, | ||
| GlobalMaterialLocalizations.delegate, | ||
| GlobalWidgetsLocalizations.delegate, | ||
| GlobalCupertinoLocalizations.delegate, | ||
| ...GlobalMaterialLocalizations.delegates, | ||
| ], | ||
| supportedLocales: const [ | ||
| Locale('en'), // English | ||
|
|
@@ -182,7 +180,7 @@ use-escaping: true | |
|
|
||
| ### Complete Widget Implementation | ||
| ```dart | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter/widgets.dart'; | ||
| import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
|
|
||
| class GreetingWidget extends StatelessWidget { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.