Best practices for Flutter Widget Structure
.cursorrules in your project root# Flutter Widget Structure ## Core Principles * **Separation of Concerns**: Keep each widget focused on a single task or functionality. * **Reusability**: Design widgets to be reusable throughout the application. * **Readability**: Use clear and concise naming conventions and organization. ## Code Style Guidelines ### Naming Conventions * **Widget Names**: Use `PascalCase` for widget names (e.g., `MyCustomWidget`). * **Variable Names**: Use `camelCase` for variable names (e.g., `myVariable`). * **File Names**: Use `snake_case` for file names (e.g., `my_custom_widget.dart`). ### Typing * **Explicit Typing**: Use explicit typing for all variables and function parameters. * **Type Annotations**: Use type annotations for function return types and variable declarations. ## Best Practices ### Widget Organization * **Keep Widgets Small**: Break down complex widgets into smaller, manageable pieces. * **Use Separate Files**: Keep each widget in its own file, unless it's a small, tightly-coupled component. * **Organize Widgets**: Organize widgets into logical folders and categories. ### Layout and Design * **Use Layout Widgets**: Use layout widgets (e.g., `Row`, `Column`, `Stack`) to manage widget positioning and sizing. * **Avoid Absolute Positioning**: Avoid using absolute positioning (e.g., `Positioned`) whenever possible. * **Use Padding and Margin**: Use padding and margin to add space between widgets. ### State Management * **Use StatefulWidget**: Use `StatefulWidget` for widgets that require state management. * **Use Provider or Riverpod**: Consider using a state management library like Provider or Riverpod for complex state management. ### Performance Optimization * **Use const**: Use `const` constructors for widgets that don't change. * **Avoid Unnecessary Rebuilds**: Avoid unnecessary rebuilds by using `shouldRebuild` and `didUpdateWidget`. ## Common Pitfalls to Avoid * **Tight Coupling**: Avoid tightly coupling widgets together, making them difficult to reuse. * **Deep Widget Trees**: Avoid creating deep widget trees, which can lead to performance issues. * **Overusing StatelessWidget**: Avoid using `StatelessWidget` for widgets that require state management. * **Not Using const**: Not using `const` constructors for widgets that don't change, leading to unnecessary rebuilds.
Comprehensive Cursor rules for Next.js 14+ with App Router, including routing, layouts, and API patterns.
Cursor rules for TypeScript with strict type checking, advanced patterns, and best practices.
Cursor rules for Tailwind CSS development with responsive design, custom components, and dark mode.
Cursor
coding
AI coding rules customize how Cursor generates and refactors code for your project. Follow these steps to install Flutter Widget Structure.
.cursor/rules, for Windsurf use .windsurfrulesComprehensive Cursor rules for Next.js 14+ with App Router, including routing, layouts, and API patterns.
Cursor rules for TypeScript with strict type checking, advanced patterns, and best practices.
Cursor rules for Tailwind CSS development with responsive design, custom components, and dark mode.