### Install and Get Skills with the 'skills' Package Source: https://github.com/flutter/skills/blob/main/tool/dart_skills_lint/skills/README.md Use these commands to activate the 'skills' package globally and then fetch the skills provided by dart_skills_lint. ```bash dart pub global activate skills skills get ``` -------------------------------- ### SKILL.md Versioning Example Source: https://github.com/flutter/skills/blob/main/tool/dart_skills_lint/documentation/knowledge/SPECIFICATION.md Demonstrates how to use the `metadata` field in the SKILL.md file to track the skill's version. ```yaml metadata: version: "1.0.0" ``` -------------------------------- ### Skill Configuration Example Source: https://github.com/flutter/skills/blob/main/tool/generator/README.md Example of a skill definition within the YAML configuration file, specifying resources for generation. ```yaml - name: flutter-layout description: "..." resources: - https://docs.flutter.dev/ui/widgets/layout - https://docs.flutter.dev/ui/layout - ../packages/flutter/lib/src/widgets/layout.md ``` -------------------------------- ### Project Structure Example Source: https://github.com/flutter/skills/blob/main/skills/flutter-apply-architecture-best-practices/SKILL.md Illustrates a recommended hybrid project structure for Flutter applications, grouping UI by feature and Data/Domain by type. ```text lib/ ├── data/ │ ├── models/ # API models │ ├── repositories/ # Repository implementations │ └── services/ # API clients, local storage wrappers ├── domain/ │ ├── models/ # Clean domain models │ └── use_cases/ # Optional business logic classes └── ui/ ├── core/ # Shared widgets, themes, typography └── features/ └── [feature_name]/ ├── view_models/ └── views/ ``` -------------------------------- ### Install Flutter Skills Source: https://github.com/flutter/skills/blob/main/README.md Installs all available Flutter agent skills into your project. The `--agent universal` flag ensures it's placed in the standard `.agents/skills` folder. ```bash npx skills add flutter/skills --skill '*' --agent universal ``` -------------------------------- ### Install Flutter Skills CLI Source: https://context7.com/flutter/skills/llms.txt Use the `npx skills` command to install or update Flutter Agent Skills in your project. The `--skill '*'` flag installs all available skills. ```bash npx skills add flutter/skills --skill '*' --agent universal ``` ```bash npx skills update ``` -------------------------------- ### Complete l10n.yaml Configuration Source: https://github.com/flutter/skills/blob/main/skills/flutter-setup-localization/SKILL.md This is a complete example of the `l10n.yaml` file. It specifies the directory for ARB files, the template ARB file, the output localization file, and enables synthetic package generation and escaping. ```yaml arb-dir: lib/l10n template-arb-file: app_en.arb output-localization-file: app_localizations.dart synthetic-package: true use-escaping: true ``` -------------------------------- ### Activate dart_skills_lint globally Source: https://github.com/flutter/skills/blob/main/tool/dart_skills_lint/README.md Install dart_skills_lint globally for command-line access across multiple projects without adding it to individual `pubspec.yaml` files. ```bash dart pub global activate dart_skills_lint ``` -------------------------------- ### Define ARB with Placeholders Source: https://github.com/flutter/skills/blob/main/skills/flutter-setup-localization/SKILL.md Use placeholders within curly braces in ARB files for dynamic data. Define placeholder types and examples in the metadata. ```json "hello": "Hello {userName}", "@hello": { "description": "A message with a single parameter", "placeholders": { "userName": { "type": "String", "example": "Bob" } } } ``` -------------------------------- ### dart_skills_lint CLI Usage Examples Source: https://context7.com/flutter/skills/llms.txt Validate skill directories using the `dart_skills_lint` CLI. Options include specifying directories, enabling quiet mode, fast failure, dry runs, and auto-fixing. ```bash dart run dart_skills_lint --skills-directory ./skills ``` ```bash dart run dart_skills_lint \ --skills-directory ./path/to/root-a \ --skills-directory ./path/to/root-b ``` ```bash dart run dart_skills_lint --skill ./skills/flutter-use-http-package ``` ```bash dart run dart_skills_lint --skills-directory ./skills --quiet ``` ```bash dart run dart_skills_lint --skills-directory ./skills --fast-fail ``` ```bash dart run dart_skills_lint --skills-directory ./skills --fix ``` ```bash dart run dart_skills_lint --skills-directory ./skills --fix-apply ``` ```bash dart run dart_skills_lint --skills-directory ./skills --generate-baseline ``` ```bash dart pub global activate dart_skills_lint dart_skills_lint --skills-directory ./skills ``` -------------------------------- ### Generate Localization Classes Source: https://github.com/flutter/skills/blob/main/skills/flutter-setup-localization/SKILL.md Run `flutter pub get` to trigger the generation of localization classes based on your ARB files. ```bash flutter pub get ``` -------------------------------- ### Host Driver Script (`test_driver/integration_test.dart`) Source: https://github.com/flutter/skills/blob/main/skills/flutter-add-integration-test/SKILL.md This script is required to run integration tests. It simply calls `integrationDriver()` to start the test process. ```dart import 'package:integration_test/integration_test_driver.dart'; Future main() => integrationDriver(); ``` -------------------------------- ### Initialize Integration Test Binding Source: https://github.com/flutter/skills/blob/main/skills/flutter-add-integration-test/SKILL.md Ensure the integration test binding is initialized at the start of your test's main function. ```dart IntegrationTestWidgetsFlutterBinding.ensureInitialized(); ``` -------------------------------- ### Generate Baseline for Dart Skills Lint Source: https://github.com/flutter/skills/blob/main/tool/dart_skills_lint/skills/dart-skills-lint-validation/SKILL.md Use this command to generate a baseline ignore file for existing issues. This helps in starting with a clean run when integrating the linter into a project with legacy code. ```bash dart run dart_skills_lint:cli --skills-directory=.agents/skills --generate-baseline ``` -------------------------------- ### Integrate linter into Dart tests Source: https://github.com/flutter/skills/blob/main/tool/dart_skills_lint/README.md Incorporate the `dart_skills_lint` package into your test suite to automatically validate skills. This example shows how to configure and run the linter within a `test/lint_skills_test.dart` file. ```dart import 'package:dart_skills_lint/dart_skills_lint.dart'; import 'package:test/test.dart'; void main() { test('Run skills linter', () async { final config = Configuration( directoryConfigs: [ DirectoryConfig( path: '../../skills', rules: {}, ignoreFile: '.agents/skills/flutter_skills_ignore.json', ), ], ); await validateSkills( skillDirPaths: ['../../skills'], resolvedRules: { 'check-relative-paths': AnalysisSeverity.error, 'check-absolute-paths': AnalysisSeverity.error, }, config: config, ); }); } ``` -------------------------------- ### Configure linter with YAML file Source: https://github.com/flutter/skills/blob/main/tool/dart_skills_lint/README.md Set up linting rules and directories by creating a `dart_skills_lint.yaml` file. Run the linter without arguments to use this configuration. ```yaml # dart_skills_lint.yaml dart_skills_lint: rules: check-relative-paths: error check-absolute-paths: error directories: - path: "~/.agents/skills" ignore_file: "~/.agents/skills/ignore.json" ``` ```bash dart run dart_skills_lint ``` -------------------------------- ### SKILL.md Instructions (Markdown Body) Source: https://github.com/flutter/skills/blob/main/tool/dart_skills_lint/documentation/knowledge/SPECIFICATION.md Illustrates how to include agent instructions and reference other files within the skill directory using Markdown in the SKILL.md file. ```markdown # Skill Instructions This skill helps the agent to perform [specific task]. [See technical details](references/DETAILS.md) Ensure you have the necessary tools installed. ``` -------------------------------- ### Execute Integration Tests Headless on Web Source: https://github.com/flutter/skills/blob/main/skills/flutter-add-integration-test/SKILL.md Run integration tests in a headless web environment using the -d web-server flag. ```bash flutter drive --driver=test_driver/integration_test.dart --target=integration_test/app_test.dart -d web-server ``` -------------------------------- ### Data Layer: Service and Repository Implementation Source: https://github.com/flutter/skills/blob/main/skills/flutter-apply-architecture-best-practices/SKILL.md Demonstrates the implementation of a Service for raw API interaction and a Repository that acts as a single source of truth, returning Domain Models. ```dart // 1. Service (Raw API interaction) class ApiClient { Future fetchUser(String id) async { // HTTP GET implementation... } } // 2. Repository (Single source of truth, returns Domain Model) class UserRepository { UserRepository({required ApiClient apiClient}) : _apiClient = apiClient; final ApiClient _apiClient; User? _cachedUser; Future getUser(String id) async { if (_cachedUser != null) return _cachedUser!; final apiModel = await _apiClient.fetchUser(id); _cachedUser = User(id: apiModel.id, name: apiModel.fullName); // Transform to Domain Model return _cachedUser!; } } ``` -------------------------------- ### Initialize Flutter App with GoRouter Source: https://github.com/flutter/skills/blob/main/skills/flutter-setup-declarative-routing/SKILL.md Sets up the `MaterialApp.router` with a `GoRouter` configuration. Includes enabling the path URL strategy for cleaner web URLs and defining basic routes with nested routes. ```dart import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:flutter_web_plugins/url_strategy.dart'; void main() { // Use path URL strategy to remove the '#' from web URLs usePathUrlStrategy(); runApp(const MyApp()); } final GoRouter _router = GoRouter( initialLocation: '/', routes: [ GoRoute( path: '/', builder: (context, state) => const HomeScreen(), routes: [ GoRoute( path: 'details/:id', builder: (context, state) => DetailsScreen(id: state.pathParameters['id']!), ), ], ), ], errorBuilder: (context, state) => ErrorScreen(error: state.error), ); class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp.router( routerConfig: _router, title: 'Routing App', ); } } ``` -------------------------------- ### Update Flutter Skills Source: https://github.com/flutter/skills/blob/main/README.md Updates all installed agent skills to their latest versions. Run this command periodically to ensure you have the most recent skill capabilities. ```bash npx skills update ``` -------------------------------- ### Basic Widget Preview Source: https://github.com/flutter/skills/blob/main/skills/flutter-add-widget-preview/SKILL.md Annotate a function returning a Widget with `@Preview` to create a basic widget preview. Configure the preview's name and group using annotation parameters. ```dart import 'package:flutter/widget_previews.dart'; import 'package:flutter/material.dart'; @Preview(name: 'My Sample Text', group: 'Typography') Widget mySampleText() { return const Text('Hello, World!'); } ``` -------------------------------- ### JSON Select Syntax for Gendered Text Source: https://github.com/flutter/skills/blob/main/skills/flutter-setup-localization/SKILL.md Use the `select` syntax in JSON for conditional strings, such as gendered text. This example shows how to define a pronoun based on gender. ```json "pronoun": "{gender, select, male{he} female{she} other{they}}", "@pronoun": { "description": "A gendered message", "placeholders": { "gender": { "type": "String" } } } ``` -------------------------------- ### Create l10n.yaml Configuration Source: https://github.com/flutter/skills/blob/main/skills/flutter-setup-localization/SKILL.md Define the input directory for ARB files, the template file, and the output localization file in `l10n.yaml`. ```yaml arb-dir: lib/l10n template-arb-file: app_en.arb output-localization-file: app_localizations.dart synthetic-package: true ``` -------------------------------- ### Add dart_skills_lint as a project dependency Source: https://github.com/flutter/skills/blob/main/tool/dart_skills_lint/README.md Include dart_skills_lint in your project's dev_dependencies to integrate linting into your development workflow. Run `dart pub get` to fetch the package. ```yaml dev_dependencies: dart_skills_lint: ^0.2.0 ``` ```bash dart pub get ``` -------------------------------- ### Execute Integration Tests on Android (Local) Source: https://github.com/flutter/skills/blob/main/skills/flutter-add-integration-test/SKILL.md Run integration tests locally on an Android device or emulator. ```bash flutter drive --driver=test_driver/integration_test.dart --target=integration_test/app_test.dart ``` -------------------------------- ### Generate All Skills Source: https://github.com/flutter/skills/blob/main/tool/generator/README.md Generates all skills defined in the default configuration file to the default output directory. ```bash dart run skills generate-skill ``` -------------------------------- ### Host apple-app-site-association File Source: https://github.com/flutter/skills/blob/main/skills/flutter-setup-declarative-routing/SKILL.md Serve this JSON content (without a `.json` extension) at `https://yourdomain.com/.well-known/apple-app-site-association` to enable Universal Links on iOS. ```json { "applinks": { "apps": [], "details": [{ "appIDs": ["TEAM_ID.com.yourcompany.yourapp"], "paths": ["*"], "components": [{"/": "/*"}] }] } } ``` -------------------------------- ### Run dart_skills_lint CLI (Global Activation) Source: https://github.com/flutter/skills/blob/main/tool/dart_skills_lint/skills/dart-skills-lint-validation/SKILL.md Use this command when dart_skills_lint is activated globally, useful for validating skills across multiple projects. ```bash dart pub global run dart_skills_lint -d .agents/skills ``` -------------------------------- ### Development Commands Source: https://github.com/flutter/skills/blob/main/tool/generator/README.md Commands to run analysis, formatting, and tests for the generator tool. ```bash dart analyze ``` ```bash dart format . ``` ```bash dart test ``` -------------------------------- ### Update All Skills Source: https://github.com/flutter/skills/blob/main/tool/generator/README.md Updates all skills defined in the default configuration file. ```bash dart run skills update-skill ``` -------------------------------- ### Generate and Use Baseline Ignore File Source: https://context7.com/flutter/skills/llms.txt Shows how to generate a baseline JSON file to suppress existing linting errors and how to use a custom ignore file path for CI/CD pipelines. This helps in managing pre-existing issues. ```bash dart run dart_skills_lint --skills-directory ./skills --generate-baseline ``` ```bash dart run dart_skills_lint \ --skills-directory ./skills \ --ignore-file ./ci/skills_ignore.json ``` ```json { "skills": { "flutter-use-http-package": [ { "ruleId": "check-trailing-whitespace", "fileName": "SKILL.md" } ], "flutter-add-widget-test": [ { "ruleId": "check-relative-paths", "fileName": "SKILL.md" } ] } } ``` -------------------------------- ### Programmatic Configuration Loading with Dart Source: https://context7.com/flutter/skills/llms.txt Illustrates how to load the dart_skills_lint configuration programmatically using `ConfigParser.loadConfig`. This is useful for building custom tooling or integrating linting into other Dart applications. It also shows how to handle parsing errors and access configuration details. ```dart import 'package:dart_skills_lint/dart_skills_lint.dart'; Future main() async { // Reads dart_skills_lint.yaml from the current directory final Configuration config = await ConfigParser.loadConfig(); if (config.parsingErrors.isNotEmpty) { for (final error in config.parsingErrors) { print('Config error: $error'); } return; } print('Configured rules: ${config.configuredRules}'); for (final dir in config.directoryConfigs) { print('Directory: ${dir.path}'); print(' Ignore file: ${dir.ignoreFile}'); print(' Rule overrides: ${dir.rules}'); } // Pass directly to validateSkills await validateSkills( skillDirPaths: config.directoryConfigs.map((d) => d.path).toList(), config: config, ); } ``` -------------------------------- ### Programmatic Navigation with GoRouter Extensions Source: https://github.com/flutter/skills/blob/main/skills/flutter-setup-declarative-routing/SKILL.md Utilize `context.go()`, `context.push()`, and `context.goNamed()` for declarative and imperative navigation. `context.pop()` is used to navigate back. ```dart // Replaces the current route stack with the target route (Declarative) context.go('/details/123'); // Pushes the target route onto the existing stack (Imperative) context.push('/details/123'); // Navigates using a named route and path parameters context.goNamed('details', pathParameters: {'id': '123'}); // Pops the current route context.pop(); ``` -------------------------------- ### Run dart_skills_lint CLI (Project Dependency) Source: https://github.com/flutter/skills/blob/main/tool/dart_skills_lint/skills/dart-skills-lint-validation/SKILL.md Use this command when dart_skills_lint is a dependency in your project's pubspec.yaml. ```bash dart run dart_skills_lint -d .agents/skills ``` -------------------------------- ### Add completion Dependency Source: https://github.com/flutter/skills/blob/main/tool/dart_skills_lint/documentation/feature_design_docs/completion_migration_plan.md Add the `completion` package as a dependency to your project using the Dart pub tool. ```bash dart pub add completion ``` -------------------------------- ### SKILL.md Metadata (YAML Frontmatter) Source: https://github.com/flutter/skills/blob/main/tool/dart_skills_lint/documentation/knowledge/SPECIFICATION.md Specifies the required and optional fields for the YAML frontmatter in the SKILL.md file, including constraints for each field. ```yaml name: "skill-name" description: "A concise summary of the skill's purpose." license: "MIT" compatibility: "Requires Python 3.10+" metadata: version: "1.0.0" author: "Jane Doe" allowed-tools: "Bash(git:*)" ``` -------------------------------- ### Implement ScaffoldWithNavBar Widget Source: https://github.com/flutter/skills/blob/main/skills/flutter-setup-declarative-routing/SKILL.md Create a `StatelessWidget` that consumes `StatefulNavigationShell` to build the UI shell, including the `NavigationBar` and handling branch switching. ```dart class ScaffoldWithNavBar extends StatelessWidget { const ScaffoldWithNavBar({ required this.navigationShell, super.key, }); final StatefulNavigationShell navigationShell; void _goBranch(int index) { navigationShell.goBranch( index, // Support navigating to the initial location when tapping the active tab. initialLocation: index == navigationShell.currentIndex, ); } @override Widget build(BuildContext context) { return Scaffold( body: navigationShell, bottomNavigationBar: NavigationBar( selectedIndex: navigationShell.currentIndex, onDestinationSelected: _goBranch, destinations: const [ NavigationDestination(icon: Icon(Icons.home), label: 'Home'), NavigationDestination(icon: Icon(Icons.settings), label: 'Settings'), ], ), ); } } ``` -------------------------------- ### Import http Package Source: https://github.com/flutter/skills/blob/main/skills/flutter-use-http-package/SKILL.md Import the `http` package into your Dart files using a prefix for clarity. ```dart import 'package:http/http.dart' as http; ``` -------------------------------- ### Adaptive Layout using LayoutBuilder Source: https://github.com/flutter/skills/blob/main/skills/flutter-build-responsive-layout/SKILL.md Switch between mobile and desktop layouts based on available screen width. Requires the 'flutter/material.dart' import. ```dart import 'package:flutter/material.dart'; const double largeScreenMinWidth = 600.0; class AdaptiveLayout extends StatelessWidget { const AdaptiveLayout({super.key}); @override Widget build(BuildContext context) { return LayoutBuilder( builder: (context, constraints) { if (constraints.maxWidth > largeScreenMinWidth) { return _buildLargeScreenLayout(); } else { return _buildSmallScreenLayout(); } }, ); } Widget _buildLargeScreenLayout() { return Row( children: [ const SizedBox(width: 250, child: Placeholder(color: Colors.blue)), const VerticalDivider(width: 1), Expanded(child: const Placeholder(color: Colors.green)), ], ); } Widget _buildSmallScreenLayout() { return const Placeholder(color: Colors.green); } } ``` -------------------------------- ### Configure MaterialApp for Localization Source: https://github.com/flutter/skills/blob/main/skills/flutter-setup-localization/SKILL.md Import generated localizations and `flutter_localizations`. Configure `MaterialApp` with delegates and supported locales. ```dart import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; // Adjust path if synthetic-package is false // ... inside build method return MaterialApp( localizationsDelegates: const [ AppLocalizations.delegate, GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, ], supportedLocales: const [ Locale('en'), // English Locale('es'), // Spanish ], home: const MyHomePage(), ); ``` -------------------------------- ### MultiPreview Implementation for Brightness Source: https://github.com/flutter/skills/blob/main/skills/flutter-add-widget-preview/SKILL.md Implement a MultiPreview class to automatically generate previews for different brightness modes (light and dark). This simplifies the process of testing widgets in various lighting conditions. ```dart import 'package:flutter/widget_previews.dart'; import 'package:flutter/material.dart'; /// Creates light and dark mode previews automatically. final class MultiBrightnessPreview extends MultiPreview { const MultiBrightnessPreview({required this.name}); final String name; @override List get previews => const [ Preview(brightness: Brightness.light), Preview(brightness: Brightness.dark), ]; @override List transform() { final previews = super.transform(); return previews.map((preview) { final builder = preview.toBuilder() ..group = 'Brightness' ..name = '$name - ${preview.brightness!.name}'; return builder.toPreview(); }).toList(); } } @MultiBrightnessPreview(name: 'Primary Card') Widget cardPreview() => const Card(child: Padding(padding: EdgeInsets.all(8.0), child: Text('Content'))); ``` -------------------------------- ### Configure pubspec.yaml for Localization Source: https://github.com/flutter/skills/blob/main/skills/flutter-setup-localization/SKILL.md Ensure `flutter_localizations` and `intl` are listed under dependencies and enable code generation in `pubspec.yaml`. ```yaml dependencies: flutter: sdk: flutter flutter_localizations: sdk: flutter intl: any ``` ```yaml flutter: generate: true ``` -------------------------------- ### Execute Integration Tests on Chrome Source: https://github.com/flutter/skills/blob/main/skills/flutter-add-integration-test/SKILL.md Run integration tests on Chrome by launching chromedriver and specifying the target and driver scripts. ```bash flutter drive --driver=test_driver/integration_test.dart --target=integration_test/app_test.dart -d chrome ``` -------------------------------- ### Add cli_completion Dependency Source: https://github.com/flutter/skills/blob/main/tool/dart_skills_lint/documentation/feature_design_docs/completion_migration_plan.md Add the `cli_completion` package as a dependency to your project using the Dart pub tool. ```bash dart pub add cli_completion ``` -------------------------------- ### Configure dart_skills_lint Rules and Directories Source: https://github.com/flutter/skills/blob/main/tool/dart_skills_lint/skills/dart-skills-lint-validation/SKILL.md Create a dart_skills_lint.yaml file to customize rules and specify skill directories for the CLI. This file is ignored when using validateSkills directly in tests. ```yaml dart_skills_lint: rules: check-relative-paths: error check-absolute-paths: error directories: - path: ".agents/skills" ``` -------------------------------- ### Run linter against skills directory Source: https://github.com/flutter/skills/blob/main/tool/dart_skills_lint/README.md Execute the linter against a specified root directory containing skills. Multiple directories can be processed by repeating the flag. ```bash dart run dart_skills_lint --skills-directory ./path/to/skills-root ``` ```bash dart run dart_skills_lint --skills-directory ./path/to/root-a --skills-directory ./path/to/root-b ``` -------------------------------- ### Test Deep Linking on iOS using simctl Source: https://github.com/flutter/skills/blob/main/skills/flutter-setup-declarative-routing/SKILL.md Use the `xcrun simctl` command to test deep links on a booted iOS simulator. This command opens the specified URL in the simulator. ```bash xcrun simctl openurl booted https://yourdomain.com/details/123 ``` -------------------------------- ### Update Root README Source: https://github.com/flutter/skills/blob/main/tool/generator/README.md Updates the root README.md file with a table of available skills using the default configuration and README file paths. ```bash dart run skills update-readme ``` -------------------------------- ### Generate Specific Skill Source: https://github.com/flutter/skills/blob/main/tool/generator/README.md Generates a specific skill by name and outputs it to a custom directory. ```bash dart run skills generate-skill --skill flutter-layout --directory ../skills ``` -------------------------------- ### Enable Flutter Driver Extension Source: https://github.com/flutter/skills/blob/main/skills/flutter-add-integration-test/SKILL.md Import and call enableFlutterDriverExtension in your application's entry point before runApp() to enable Flutter Driver. ```dart import 'package:flutter_driver/driver_extension.dart'; void main() { enableFlutterDriverExtension(); // ... runApp() call } ``` -------------------------------- ### Validate Skills in Default Directory Source: https://github.com/flutter/skills/blob/main/tool/generator/README.md Validates skills located in the default 'skills' directory. ```bash dart run skills validate-skill ``` -------------------------------- ### Build Test APK for Firebase Test Lab Source: https://github.com/flutter/skills/blob/main/skills/flutter-add-integration-test/SKILL.md Build the test APK required for Firebase Test Lab using Gradle. ```bash ./gradlew app:assembleAndroidTest ``` -------------------------------- ### Validate an individual skill directory Source: https://github.com/flutter/skills/blob/main/tool/dart_skills_lint/README.md Use the `--skill` or `-s` flag to lint a single, specific skill directory. ```bash dart run dart_skills_lint --skill ./path/to/my-single-skill ``` -------------------------------- ### ProfileView for UI Rendering Source: https://github.com/flutter/skills/blob/main/skills/flutter-apply-architecture-best-practices/SKILL.md Use this View as a stateless widget to display user profile information. It listens to the ProfileViewModel for state updates and renders the UI accordingly, showing a loading indicator or user details. ```dart // 4. View (Dumb UI component) class ProfileView extends StatelessWidget { const ProfileView({super.key, required this.viewModel}); final ProfileViewModel viewModel; @override Widget build(BuildContext context) { return ListenableBuilder( listenable: viewModel, builder: (context, _) { if (viewModel.isLoading) { return const Center(child: CircularProgressIndicator()); } final user = viewModel.user; if (user == null) { return const Center(child: Text('User not found')); } return Column( children: [ Text(user.name), ElevatedButton( onPressed: () => viewModel.loadProfile(user.id), child: const Text('Refresh'), ), ], ); }, ); } } ``` -------------------------------- ### Add http Package Dependency Source: https://github.com/flutter/skills/blob/main/skills/flutter-use-http-package/SKILL.md Add the `http` package to your Flutter project using the `flutter pub add` command in the terminal. ```bash flutter pub add http ``` -------------------------------- ### UI Integration with FutureBuilder Source: https://github.com/flutter/skills/blob/main/skills/flutter-use-http-package/SKILL.md Displays a list of photos fetched from the network. It uses `FutureBuilder` to handle asynchronous data loading, showing a loading indicator, data, or error messages. ```dart class PhotoGallery extends StatefulWidget { const PhotoGallery({super.key}); @override State createState() => _PhotoGalleryState(); } class _PhotoGalleryState extends State { late Future> _futurePhotos; @override void initState() { super.initState(); // Initialize Future once to prevent re-fetching on rebuilds _futurePhotos = fetchPhotos(); } @override Widget build(BuildContext context) { return FutureBuilder>( future: _futurePhotos, builder: (context, snapshot) { if (snapshot.hasData) { final photos = snapshot.data!; return ListView.builder( itemCount: photos.length, itemBuilder: (context, index) => ListTile( leading: Image.network(photos[index].thumbnailUrl), title: Text(photos[index].title), ), ); } else if (snapshot.hasError) { return Center(child: Text('Error: ${snapshot.error}')); } // Default loading state return const Center(child: CircularProgressIndicator()); }, ); } } ``` -------------------------------- ### Performance Profiling Driver Script (`test_driver/perf_driver.dart`) Source: https://github.com/flutter/skills/blob/main/skills/flutter-add-integration-test/SKILL.md Use this driver script when you need to capture performance metrics by wrapping test actions in `binding.traceAction()`. It processes and saves timeline data. ```dart import 'package:flutter_driver/flutter_driver.dart' as driver; import 'package:integration_test/integration_test_driver.dart'; Future main() { return integrationDriver( responseDataCallback: (data) async { if (data != null) { final timeline = driver.Timeline.fromJson( data['scrolling_timeline'] as Map, ); final summary = driver.TimelineSummary.summarize(timeline); await summary.writeTimelineToFile( 'scrolling_timeline', pretty: true, includeSummary: true, ); } }, ); } ``` -------------------------------- ### Custom Preview with Runtime Transformation Source: https://github.com/flutter/skills/blob/main/skills/flutter-add-widget-preview/SKILL.md Define a custom Preview class to apply transformations at runtime, such as modifying the preview's name and theme. This is useful for applying consistent styling or naming conventions across multiple previews. ```dart import 'package:flutter/widget_previews.dart'; import 'package:flutter/material.dart'; final class TransformativePreview extends Preview { const TransformativePreview({ super.name, super.group, }); PreviewThemeData _themeBuilder() { return PreviewThemeData( materialLight: ThemeData.light(), materialDark: ThemeData.dark(), ); } @override Preview transform() { final originalPreview = super.transform(); final builder = originalPreview.toBuilder(); builder ..name = 'Transformed - ${originalPreview.name}' ..theme = _themeBuilder; return builder.toPreview(); } } @TransformativePreview(name: 'Custom Themed Button') Widget myButton() => const ElevatedButton(onPressed: null, child: Text('Click')); ``` -------------------------------- ### Add Integration Test Dependencies Source: https://github.com/flutter/skills/blob/main/skills/flutter-add-integration-test/SKILL.md Add the necessary development dependencies for integration testing to your pubspec.yaml file. ```bash flutter pub add 'dev:integration_test:{"sdk":"flutter"}' flutter pub add 'dev:flutter_test:{"sdk":"flutter"}' ``` -------------------------------- ### ProfileViewModel for State Management Source: https://github.com/flutter/skills/blob/main/skills/flutter-apply-architecture-best-practices/SKILL.md Implement this ViewModel to manage the state and presentation logic for a user profile. It extends ChangeNotifier to notify listeners of state changes and handles asynchronous data loading. ```dart // 3. ViewModel (State management and presentation logic) class ProfileViewModel extends ChangeNotifier { ProfileViewModel({required UserRepository userRepository}) : _userRepository = userRepository; final UserRepository _userRepository; User? _user; User? get user => _user; bool _isLoading = false; bool get isLoading => _isLoading; Future loadProfile(String id) async { _isLoading = true; notifyListeners(); try { _user = await _userRepository.getUser(id); } finally { _isLoading = false; notifyListeners(); } } } ``` -------------------------------- ### Standard Integration Test (`integration_test/app_test.dart`) Source: https://github.com/flutter/skills/blob/main/skills/flutter-add-integration-test/SKILL.md Write end-to-end tests for your Flutter app using the `integration_test` package. Ensure `IntegrationTestWidgetsFlutterBinding.ensureInitialized()` is called and widgets have `ValueKey`s for reliable targeting. ```dart import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; import 'package:my_app/main.dart'; void main() { IntegrationTestWidgetsFlutterBinding.ensureInitialized(); group('End-to-end test', () { testWidgets('tap on the floating action button, verify counter', (tester) async { // Load app widget. await tester.pumpWidget(const MyApp()); // Verify the counter starts at 0. expect(find.text('0'), findsOneWidget); // Find the floating action button to tap on. final fab = find.byKey(const ValueKey('increment')); // Emulate a tap on the floating action button. await tester.tap(fab); // Trigger a frame and wait for animations. await tester.pumpAndSettle(); // Verify the counter increments by 1. expect(find.text('1'), findsOneWidget); }); }); } ``` -------------------------------- ### Define ARB with Plurals Source: https://github.com/flutter/skills/blob/main/skills/flutter-setup-localization/SKILL.md Handle quantity-based string variations using the `plural` syntax in ARB files. The `other` case is mandatory. ```json "nWombats": "{count, plural, =0{no wombats} =1{1 wombat} other{{count} wombats}}", "@nWombats": { "description": "A plural message", "placeholders": { "count": { "type": "num", "format": "compact" } } } ``` -------------------------------- ### Dynamic Rule Resolution in Entry Point Dart Source: https://github.com/flutter/skills/blob/main/tool/dart_skills_lint/documentation/feature_design_docs/legacy_patterns_report.md Unify rule resolution into a single dynamic pattern by mapping directory config rules directly to creating a Validator instance. This avoids hardcoding rules in the directory loop. ```dart // Pre-resolve directory rules by name in entry_point.dart final Map resolvedLocalRules = {}; // Fallback to global rules for (final rule in globalRules) { resolvedLocalRules[rule.name] = rule.severity; } // Override with specific directory rules for (final key in dirConfig.rules.keys) { resolvedLocalRules[key] = dirConfig.rules[key]!; } // Create Validator with these local overrides final localValidator = Validator( rules: resolvedLocalRules.entries.map((e) => CheckType(name: e.key, defaultSeverity: e.value)).toSet(), ); ``` -------------------------------- ### Define ARB File Content Source: https://github.com/flutter/skills/blob/main/skills/flutter-setup-localization/SKILL.md Define localized strings and their descriptions in ARB JSON format. The template file serves as the base for other locales. ```json { "helloWorld": "Hello World!", "@helloWorld": { "description": "The conventional newborn programmer greeting" } } ``` ```json { "helloWorld": "¡Hola Mundo!" } ``` -------------------------------- ### Add Localization Dependencies Source: https://github.com/flutter/skills/blob/main/skills/flutter-setup-localization/SKILL.md Add `flutter_localizations` and `intl` to your project's dependencies using the Flutter CLI. ```bash flutter pub add flutter_localizations --sdk=flutter flutter pub add intl:any ``` -------------------------------- ### Configure Associated Domains in Runner.entitlements Source: https://github.com/flutter/skills/blob/main/skills/flutter-setup-declarative-routing/SKILL.md Add the `com.apple.developer.associated-domains` key to your `Runner.entitlements` file to specify your app's associated domains for deep linking. ```xml com.apple.developer.associated-domains applinks:yourdomain.com ``` -------------------------------- ### Flutter Todo List Widget Source: https://github.com/flutter/skills/blob/main/skills/flutter-add-widget-test/SKILL.md The target widget for testing, a simple Todo list with add and dismiss functionality. ```dart import 'package:flutter/material.dart'; class TodoList extends StatefulWidget { const TodoList({super.key}); @override State createState() => _TodoListState(); } class _TodoListState extends State { final todos = []; final controller = TextEditingController(); @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Column( children: [ TextField(controller: controller), Expanded( child: ListView.builder( itemCount: todos.length, itemBuilder: (context, index) { final todo = todos[index]; return Dismissible( key: Key('$todo$index'), onDismissed: (_) => setState(() => todos.removeAt(index)), child: ListTile(title: Text(todo)), ); }, ), ), ], ), floatingActionButton: FloatingActionButton( onPressed: () { setState(() { todos.add(controller.text); controller.clear(); }); }, child: const Icon(Icons.add), ), ), ); } } ``` -------------------------------- ### Test Deep Linking on Android using ADB Source: https://github.com/flutter/skills/blob/main/skills/flutter-setup-declarative-routing/SKILL.md Use the Android Debug Bridge (ADB) to simulate opening a deep link on an Android device or emulator. This command tests the `android.intent.action.VIEW` intent. ```bash adb shell 'am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "https://yourdomain.com/details/123"' com.yourcompany.yourapp ``` -------------------------------- ### Flutter Agent Skill File Structure Source: https://context7.com/flutter/skills/llms.txt An Agent Skill is a directory containing a `SKILL.md` file with YAML metadata and Markdown instructions. The `name` field in the YAML must match the directory name. ```markdown flutter-use-http-package/ ├── SKILL.md # Required: YAML metadata + agent instructions ├── scripts/ # Optional: executable helper scripts ├── references/ # Optional: supplementary documentation └── assets/ # Optional: static resources ``` ```markdown --- name: flutter-use-http-package description: Use the `http` package to execute GET, POST, PUT, or DELETE requests. Use when you need to fetch from or send data to a REST API. license: BSD-3-Clause compatibility: Flutter 3.x+ allowed-tools: Bash(flutter:*) Bash(dart:*) metadata: version: "1.0.0" author: flutter-team --- # Implementing Flutter Networking Add the `http` package and configure platform permissions before making requests... ``` -------------------------------- ### Load App UI in Integration Test Source: https://github.com/flutter/skills/blob/main/skills/flutter-add-integration-test/SKILL.md Load your application's UI into the test environment using pumpWidget. ```dart await tester.pumpWidget(MyApp()); ``` -------------------------------- ### Agent Skill Directory Structure Source: https://github.com/flutter/skills/blob/main/tool/dart_skills_lint/documentation/knowledge/SPECIFICATION.md Defines the standard flat and predictable structure for an agent skill directory. The SKILL.md file is mandatory, while scripts, references, and assets are optional. ```text skill-name/ ├── SKILL.md # Required: Metadata + Instructions ├── scripts/ # Optional: Executable code (Python, Bash, JS, etc.) ├── references/ # Optional: Deep-dive documentation and templates └── assets/ # Optional: Static resources (images, schemas, etc.) ``` -------------------------------- ### Android Internet Permission Source: https://github.com/flutter/skills/blob/main/skills/flutter-use-http-package/SKILL.md Configure Android to allow internet access by adding the `INTERNET` permission to your `AndroidManifest.xml` file. ```xml ```