Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions resources/flutter_skills.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@
1. Defining Widget Previews:
* To preview a widget, use the `@Preview` annotation defined in `package:flutter/widget_previews.dart`.
* This annotation can be applied to top-level functions that return a `Widget` or `WidgetBuilder`, static methods within a class that return a `Widget` or `WidgetBuilder`, or public `Widget` constructors and factories with no required arguments.
* A basic example involves importing `package:flutter/widget_previews.dart` and `package:flutter/material.dart`, then defining a function annotated with `@Preview` that returns a `Widget`, such as a `Text` widget. For instance:
* A basic example involves importing `package:flutter/widget_previews.dart` and `package:flutter/widgets.dart` (or `package:material_ui/material_ui.dart` / `package:cupertino_ui/cupertino_ui.dart` when previewing design widgets), then defining a function annotated with `@Preview` that returns a `Widget`, such as a `Text` widget. For instance:
```dart
import 'package:flutter/widget_previews.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

@Preview(name: 'My Sample Text')
Widget mySampleText() {
Expand Down Expand Up @@ -234,11 +234,11 @@
1. **Create a new Flutter application**:
* Use the command `flutter create <app-name>`. For example, `flutter create deeplink_cookbook`.

2. **Add the `go_router` package as a dependency**:
* Run `flutter pub add go_router`. The Flutter team maintains the `go_router` package, which offers a simple API for complex routing scenarios.
2. **Add the `go_router` and `material_ui` packages as dependencies**:
* Run `flutter pub add go_router material_ui`. The Flutter team maintains the `go_router` package, which offers a simple API for complex routing scenarios.

3. **Configure `MaterialApp.router` with a `GoRouter` object**:
* In your `main.dart` file, import `package:go_router/go_router.dart'` and `package:flutter/material.dart'`.
* In your `main.dart` file, import `package:go_router/go_router.dart` and `package:material_ui/material_ui.dart`.
* Create a `GoRouter` object that defines your application's routes. This object will handle routing, including paths like '/' and '/details'.
* Set up your `main` function to run `MaterialApp.router` and provide it with the `routerConfig` property, which should be your `GoRouter` object.
* For example, you can define routes within the `GoRouter` object using `GoRoute` for different paths and their corresponding builders.
Expand Down Expand Up @@ -352,18 +352,14 @@
* This file can be used to specify options like `synthetic-package: false` to generate localized messages directly into source files instead of a synthetic package. You can also specify `arb-dir` or `output-dir` in this file.

4. **Configure `MaterialApp` or `CupertinoApp`**:
* Import the `flutter_localizations` library.
* Specify `localizationsDelegates` and `supportedLocales` for your `MaterialApp` or `CupertinoApp`. For example:
* Import `package:material_ui/material_ui.dart` (for `MaterialApp`) or `package:cupertino_ui/cupertino_ui.dart` (for `CupertinoApp`), rather than importing Material or Cupertino delegates from `flutter_localizations`.
* Specify `localizationsDelegates` and `supportedLocales` for your `MaterialApp` or `CupertinoApp` using `GlobalMaterialLocalizations.delegates` or `GlobalCupertinoLocalizations.delegates`. For example:
```dart
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:material_ui/material_ui.dart';
// ...
return const MaterialApp(
title: 'Localizations Sample App',
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
localizationsDelegates: GlobalMaterialLocalizations.delegates,
Comment thread
chunhtai marked this conversation as resolved.
Resolved
supportedLocales: [
Locale('en'), // English
Locale('es'), // Spanish
Expand Down
30 changes: 30 additions & 0 deletions rules/flutter-ui-packages.md
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.
30 changes: 30 additions & 0 deletions rules/flutter-ui-packages.mdc
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.
2 changes: 1 addition & 1 deletion skills/flutter-add-integration-test/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Copy and follow this checklist to implement and verify integration tests.
### Standard Integration Test (`integration_test/app_test.dart`)

```dart
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:my_app/main.dart';
Expand Down
6 changes: 3 additions & 3 deletions skills/flutter-add-widget-preview/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Follow the appropriate conditional workflow to launch and interact with the Widg
### Basic Preview
```dart
import 'package:flutter/widget_previews.dart';
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';

@Preview(name: 'Submit Button', group: 'Form Controls')
Widget submitButtonPreview() => const ElevatedButton(
Expand All @@ -95,7 +95,7 @@ Widget submitButtonPreview() => const ElevatedButton(
### Custom Preview with PreviewThemeData and Transformation
```dart
import 'package:flutter/widget_previews.dart';
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';

final class ThemedPreview extends Preview {
const ThemedPreview({
Expand Down Expand Up @@ -156,7 +156,7 @@ Widget themedButtonPreview() => const ElevatedButton(
### MultiPreview Implementation
```dart
import 'package:flutter/widget_previews.dart';
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';

/// Creates light and dark mode previews automatically.
final class MultiBrightnessPreview extends MultiPreview {
Expand Down
4 changes: 2 additions & 2 deletions skills/flutter-add-widget-test/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Apply the following conditional logic based on the type of interaction or state

**Target Widget (`lib/todo_list.dart`):**
```dart
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';

class TodoList extends StatefulWidget {
const TodoList({super.key});
Expand Down Expand Up @@ -117,8 +117,8 @@ class _TodoListState extends State<TodoList> {

**Test Implementation (`test/todo_list_test.dart`):**
```dart
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:material_ui/material_ui.dart';
import 'package:my_app/todo_list.dart';

void main() {
Expand Down
4 changes: 2 additions & 2 deletions skills/flutter-build-responsive-layout/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Follow this workflow to prevent UI elements from stretching unnaturally on large
Demonstrates switching between a mobile and desktop layout based on available width.

```dart
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';

const double largeScreenMinWidth = 600.0;

Expand Down Expand Up @@ -110,7 +110,7 @@ class AdaptiveLayout extends StatelessWidget {
Demonstrates preventing a widget from consuming all horizontal space.

```dart
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';

class ConstrainedContent extends StatelessWidget {
const ConstrainedContent({super.key});
Expand Down
8 changes: 4 additions & 4 deletions skills/flutter-setup-declarative-routing/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Follow this workflow to bootstrap a new Flutter application with `go_router` and

### Task Progress
- [ ] Create the Flutter application.
- [ ] Add the `go_router` dependency.
- [ ] Add the `go_router` and `material_ui` dependencies.
- [ ] Configure the URL strategy for web/deep linking.
- [ ] Implement the `GoRouter` configuration.
- [ ] Bind the router to `MaterialApp.router`.
Expand All @@ -39,16 +39,16 @@ Run the following commands to create the app and add the required routing packag
```bash
flutter create <app-name>
cd <app-name>
flutter pub add go_router
flutter pub add go_router material_ui
```

### 2. Configure the Router
Define a top-level `GoRouter` instance. Handle authentication or state-based routing using the `redirect` parameter.

```dart
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:flutter_web_plugins/url_strategy.dart';
import 'package:go_router/go_router.dart';
import 'package:material_ui/material_ui.dart';

void main() {
// Use path URL strategy to remove the '#' from web URLs
Expand Down
10 changes: 4 additions & 6 deletions skills/flutter-setup-localization/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion skills/flutter-use-http-package/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:material_ui/material_ui.dart';

// 1. Top-level parsing function for Isolate
List<Photo> parsePhotos(String responseBody) {
Expand Down
Loading