Flutter MVVM Riverpod Guidelines

Flutter MVVM Riverpod Guidelines

Gives a coding agent Flutter rules: MVVM folder structure, Riverpod state, naming and import conventions, Material widgets, theming and performance habits.


description: "Cursor rules for Flutter development with MVVM architecture, Riverpod state management, Material widgets, and Dart style guidelines."
globs: **/*.dart
alwaysApply: false


Code style and structure

  • Write concise and efficient source code.
  • Strive for source code that is easy to read and maintain, and provide accurate examples.
  • Avoid duplication of code: modularise widgets and functions into reusable components.
  • Use descriptive variable names: use names with auxiliary verbs such as isLoading, hasError.

Directory structure under /lib.

  • /lib/models/: data models and type definitions (Models)
  • /lib/viewmodels/: state management and business logic (ViewModel)
  • /lib/views/widgets/: reusable widgets (View)
  • /lib/views/screens/: per-screen widgets (View)
  • /lib/services/: service classes for API calls and data access
  • /lib/utils/: helper functions and constants

Naming conventions

  • Directories and files: use snakeCase (e.g. auth_wizard.dart).
  • UpperCamelCase: use for class names/enumerations/typedefs/type parameters, etc.
  • LowerCamelCase: used for variables/functions/class members (properties, methods), etc.
  • lowercase_with_underscores (snakeCase): for files/directories/packages/libraries, etc.

Import.

  • Place imports starting with dart: first (use lowercase_with_underscores for the import prefix).
  • Next, import third-party packages (package:).
  • Finally, import relative paths and files in the project.

Using Dart.

  • Take advantage of type safety: use static typing in all code and utilise type inference wherever possible.

UI and styling.

  • Use Material widgets.
  • Unify theming: use ThemeData to apply consistent styles.

Performance optimisation.

  • Prefer StatelessWidget when state is not required.
  • Make use of const constructors: if widgets are immutable, use const to optimise builds.

State management.

  • Use riverpod to implement efficient state management.
  • Manage state within the ViewModel and link it to the View.

Software architecture

Use MVVM (Model View ViewModel).

Key rules.

  • To improve code readability, lines should not exceed 80 characters in length.
  • Use braces {} for all flow control structures (if, for, while, etc.).
  • Use comment-outs proactively to help understand and maintain code.
  • Use single quotes, avoid the use of double quotes and use consistent string literals to improve readability.

Public domain (CC0 1.0) · by awesome-cursorrules contributors · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 12,318 prompts

More by @OpenSourceBuffGuy

See all
Blueprint Mode prompt image

Blueprint Mode

Turns a coding agent into a blunt, sarcastic senior engineer that picks a structured workflow (debug, express, main, loop), verifies facts and self-corrects.

sub-agent, ai-personality, coding, debugging, plan-then-execute, task-decomposition, self-critique, tool-use, conditional-logic, guardrails, blunt, sarcastic, for-developers, best-practices, long-form, advanced, structured-output, code-generation, checklist

Conversion Rate Optimization Expert prompt image

Conversion Rate Optimization Expert

Acts as a conversion rate optimisation specialist that audits a funnel, finds friction and designs statistically valid A/B tests to lift conversions.

system-prompt, act-as, ab-testing, ecommerce, saas, landing-pages, ui-ux, psychology, audit, data-analysis, google-analytics, expert-advice, for-marketers, for-online-sellers, for-product-managers, report, structured-output, xml-tags, guardrails, statistics, prioritization, gap-analysis, long-form, advanced, lead-generation, user-research

Miniature City Diorama Rising From a Map prompt image

Miniature City Diorama Rising From a Map

Draws a top-down geographic map of a country with a detailed miniature 3D diorama of one city rising from its true location.

image-prompt, nano-banana, placeholders, 3d-render, miniature, maps, landmarks, cityscape, architecture, photorealistic, cinematic, soft-lighting, studio-lighting, bokeh, square-format, aerial-view, macro, geography, travel

Reviews

Loading reviews…

Discussion

Loading comments…