Instruction file imported from vasu-nageshri-simform/Get_it (
.github/instructions/code-style.instructions.md). Copyright stays with the author.
Naming Conventions
- Variables/Methods: lowerCamelCase (e.g.,
fetchUserData()) - Constants: lowerCamelCase (e.g.,
maxRetries) - Private members: Prefix with underscore (e.g.,
_validateForm()) - Booleans: Use positive phrasing (e.g.,
isEnabled,hasError)
File Naming Standards
- All files: Use snake_case naming
- Navigation Model files: Always suffix with
_nav_dm.dart- e.g.,user_profile_nav_dm.dart - Request models: Always suffix with
_req_dm.dart- e.g.,login_req_dm.dart - Response models: Always suffix with
_res_dm.dart- e.g.,login_res_dm.dart - Cubit file: Always suffix with
_cubit.dart- e.g.,user_profile_cubit.dart - State file: Always suffix with
_state.dart- e.g.,user_profile_state.dart - Screen files: Always suffix with
_screen.dart- e.g.,user_profile_screen.dart
Class Naming Standards
- All classes: Use UpperCamelCase
- Model classes: Always suffix with
Dm- e.g.,UserProfileDm,LoginReqDm - Cubit class: Always suffix with
Cubit- e.g.,UserProfileCubit - State class: Always suffix with
State- e.g.,UserProfileState - Screen classes: Always suffix with
Screen- e.g.,UserProfileScreen - Widget classes: Use descriptive names without suffixes - e.g.,
ProfileCard,LoadingIndicator- If needed use suffix
Widget- e.g.,ProfileCardWidget
- If needed use suffix
Modern Dart 3 Features
- Records:
(String, int) getUserInfo() => ('John', 25); - Pattern Matching and Switch expressions:
final value = switch(response) { Success(data:var d) => d, Error() => null }; - Sealed Classes: For exhaustive type hierarchies like API states
UI Development Guidelines
- Use Gap instead of SizedBox for spacing:
Gap(8.w)instead ofSizedBox(width: 8.w) - Avoid separate methods for single-use widgets - inline them instead
- Minimize unnecessary comments - only add for complex logic, separations in large files, or TODOs
- Use responsive extensions:
.w,.h,.r,.spfor all sizing - Business logic in models: Add computed properties to data models for UI logic
- Use type-safe asset references:
Assets.vectors.iconName.svg()instead of hardcoded paths
Development & Performance Guidelines
- Always ask for more information if you are not sure about something rather than making assumptions
- Each widget should be in its own file with the same name as the widget class
- Avoid creating functions to return widgets; instead, use widget classes
- Use
constconstructors for widgets and classes - Always check
lib/utilities/extensions/for extensions method that can be used to simplify code and avoid boilerplate - Use
RepaintBoundaryfor widgets that need to be repainted separately to improve performance - Implement pagination for long lists using
paginated_list.dart - Prefer stateless widgets over stateful widgets when possible
- Use lazy loading for heavy resources
- Properly dispose of controllers, animations, and stream subscriptions
- Use weak references for callbacks to avoid memory leaks
- Implement efficient caching strategies
- Utilise isolate for heavy computations
- Always run
dart run build_runner build -dafter store, model, asset or env file changes - Avoid to create, modify or refer (as context) the generated files (
*.g.dart) - Avoid creating sample demo code and ask for which screen/module is to be modified
- Follow software engineering best practices, principles and design patterns like SOLID, DRY, returning early in a function, etc
Documentation
- Format comments like sentences.
- Use
///doc comments to document members and types; don't use block comments for documentation. - Prefer writing doc comments for public APIs.
- Consider writing doc comments for private APIs.
- Consider including explanations of terminology, links, and references in library-level docs.
- Start doc comments with a single-sentence summary.
- Separate the first sentence of a doc comment into its own paragraph.
- Use square brackets in doc comments to refer to in-scope identifiers.
- Use prose to explain parameters, return values, and exceptions.
- Put doc comments before metadata annotations.
- Document why code exists or how it should be used, not just what it does.
- Avoid unnecessary comments - only comment complex logic, separations in large files, or TODOs.
Code Quality and Linting
- Run
dart formatto format your code before committing - Run
dart analyzeto check for any issues - Use
dart fix --applyto automatically fix common issues - Follow rules mentioned in
analysis_options.yamlfile
Resources
Refer to the following resources for further guidance and best practices:
- Effective Dart for best practices
- Flutter Documentation for official guides and API references
- Very good code lint for code quality