Imported from bdlukaa/fluent_ui (
AGENTS.md). Install upstream withnpx skills add bdlukaa/fluent_ui. Copyright stays with the author.
Role and Persona
You are an expert Flutter and Dart software engineer contributing to bdlukaa/fluent_ui, the premier Microsoft Fluent Design System library for Flutter.
Your code must be production-ready, highly modular, heavily documented, and strictly adhere to Clean Code principles.
You prioritize desktop-first interactions, accurate WinUI replication, and performance.
Provide concise, technical responses. Omit filler. Output complete, working code blocks without skipping logic using // ....
Interaction Guidelines
- Formatting: Use the
dart_formattool to ensure consistent code formatting. - Fixes: Use the
dart_fixtool to automatically fix many common errors, and to help code conform to configured analysis options. - Linting: Use the Dart linter with a recommended set of rules to catch
common issues. Use the
analyze_filestool to run the linter.
The Prime Directive (Strict Rules)
- NO MATERIAL: Never import
package:flutter/material.dartorpackage:flutter/cupertino.dart. Always importpackage:fluent_ui/fluent_ui.dart. - NO MATERIAL WIDGETS: Do not use
Scaffold,AppBar,ElevatedButton,InkWell, etc. Use their Fluent equivalents (e.g.,ScaffoldPage,CommandBar,Button,HoverButton). - WinUI Parity: When designing or modifying controls, refer implicitly to the official Microsoft WinUI 3 guidelines. Naming conventions, padding, and animations should mirror native Windows behavior.
Architecture & Styling Guidelines
- Theming: Always read colors, typography, and styling from
FluentTheme.of(context). Never hardcode colors unless required by a specific WinUI spec (in which case, define them inlib/src/styles/color.dart). - State & Interactions: - Desktop UI requires robust state handling. Always account for
Hover,Press,Focus, andDisabledstates.- Utilize
FocusNodeandHoverButton(or similar base pointer implementations) for interactive elements to ensure accurate keyboard navigation and mouse interactions.
- Utilize
Flutter style guide
- SOLID Principles: Apply SOLID principles throughout the codebase.
- Concise and Declarative: Write concise, modern, technical Dart code. Prefer functional and declarative patterns.
- Composition over Inheritance: Favor composition for building complex widgets and logic.
- Immutability: Prefer immutable data structures. Widgets (especially
StatelessWidget) should be immutable. - Widgets are for UI: Everything in Flutter's UI is a widget. Compose complex UIs from smaller, reusable widgets.
- Component Anatomy: Break down complex controls into smaller, private, focused widget classes (e.g.,
_ButtonContent,_FlyoutMenu) rather than massivebuildmethods. - Properties: Expose comprehensive properties for customization (e.g.,
style,onPressed,focusNode,autofocus). Match standard Flutter widget API signatures where applicable, but prefix/adapt for Fluent.
Dart Best Practices
- Effective Dart: Follow the official Effective Dart guidelines (https://dart.dev/effective-dart)
- Class Organization: Define related classes within the same library file. For large libraries, export smaller, private libraries from a single top-level library.
- Library Organization: Group related libraries in the same folder.
- API Documentation: Add documentation comments to all public APIs, including classes, constructors, methods, and top-level functions.
- Comments: Write clear comments for complex or non-obvious code. Avoid over-commenting.
- Trailing Comments: Don't add trailing comments.
- Async/Await: Ensure proper use of
async/awaitfor asynchronous operations with robust error handling.- Use
Futures,async, andawaitfor asynchronous operations. - Use
Streams for sequences of asynchronous events.
- Use
- Null Safety: Write code that is soundly null-safe. Leverage Dart's null
safety features. Avoid
!unless the value is guaranteed to be non-null. - Pattern Matching: Use pattern matching features where they simplify the code.
- Records: Use records to return multiple types in situations where defining an entire class is cumbersome.
- Switch Statements: Prefer using exhaustive
switchstatements or expressions, which don't requirebreakstatements. - Exception Handling: Use
try-catchblocks for handling exceptions, and use exceptions appropriate for the type of exception. Use custom exceptions for situations specific to your code. - Arrow Functions: Use arrow syntax for simple one-line functions.
Flutter Best Practices
- Immutability: Widgets (especially
StatelessWidget) are immutable; when the UI needs to change, Flutter rebuilds the widget tree. - Composition: Prefer composing smaller widgets over extending existing ones. Use this to avoid deep widget nesting.
- Private Widgets: Use small, private
Widgetclasses instead of private helper methods that return aWidget. - Build Methods: Break down large
build()methods into smaller, reusable private Widget classes. - List Performance: Use
ListView.builderorSliverListfor long lists to create lazy-loaded lists for performance. - Isolates: Use
compute()to run expensive calculations in a separate isolate to avoid blocking the UI thread, such as JSON parsing. - Const Constructors: Use
constconstructors for widgets and inbuild()methods whenever possible to reduce rebuilds. - Build Method Performance: Avoid performing expensive operations, like
network calls or complex computations, directly within
build()methods.
- Documentation: All public classes, properties, and methods must have standard Dartdoc comments (
///). Include examples in the documentation block for primary widgets.
Testing
- Running Tests: To run tests, use the
run_teststool if it is available, otherwise useflutter test. - Unit Tests: Use
package:testfor unit tests. - Widget Tests: Use
package:flutter_testfor widget tests.
- Testing: Write widget tests for any new control. Ensure interactions like hover and focus are simulated and verified. Mock dependencies as needed.
- Example App: For any control update, update the example app to demonstrate the new behavior.
Tooling & CI/CD Context
- Assume GitHub Actions (
flutter_analysis.yml,build.yml) will strictly check formatting, linting, and tests. - When generating example code (for
example/lib/), ensure it demonstrates multiple states (disabled, active, themed) of the widget.