main

A set of Cursor rules for Flutter and Dart development. It covers readable code, project organization, error handling, performance, security, and common Flutter practices.

In plain words
What is it for?
Use it to guide code generation and review in Flutter projects, including widget structure, state management, naming, error handling, and safe handling of credentials and user input.
Why use it?
It gives an AI coding assistant consistent guidance for making changes that fit the project’s style and avoid common development mistakes.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/bellmemo/bell-memo-android/main
Clone the repo
git clone --depth 1 https://github.com/BellMemo/bell-memo-android

Made for: Cursor.

Per session 3,061 This file is loaded in full into every session.
When invoked 3,061 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.03061 $0.03061
Opus 5 $0.01530 $0.01530
Sonnet 5 $0.00612 $0.00612
Haiku 4.5 $0.00306 $0.00306

Measured 2d ago against content hash 63baeb05bada, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

main scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/main.mdc · 342 lines

How it starts

The opening of the file, as written. The whole thing — 342 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Cursor AI 规则 - 通用开发指南

代码风格与最佳实践

通用原则

  • 编写清晰、可读、可维护的代码
  • 遵循项目现有的代码风格和约定
  • 优先使用显式而非隐式代码
  • 使用有意义的变量和函数名
  • 保持函数小而专注,单一职责原则
  • 避免深层嵌套(最多 3-4 层)
  • 注释复杂逻辑,但优先编写自文档化代码

代码组织

  • 将相关代码组织在一起
  • 分离关注点(UI、业务逻辑、数据层)
  • 使用一致的文件和文件夹命名约定
  • 保持文件专注,避免上帝类/文件
  • 组织导入:标准库优先,然后是第三方库,最后是本地文件

错误处理

  • 始终显式处理错误
  • 提供有意义的错误消息
  • 使用适当的错误处理机制(try-catch、Result 类型等)
  • 永远不要静默吞掉错误
  • 适当记录错误以便调试

性能

  • 避免过早优化
  • 优化前先进行性能分析
  • 注意内存使用
  • 只优化关键路径
  • 在适当的时候使用懒加载
  • 缓存昂贵的计算(当有益时)

安全性

  • 永远不要提交密钥、API 密钥或凭证
  • 验证和清理用户输入
  • 对数据库操作使用参数化查询
  • 遵循最小权限原则
  • 保持依赖项更新
  • 审查第三方包的安全影响

Flutter/Dart 特定规则

Dart 风格指南

  • 遵循官方 Dart 风格指南:https://dart.dev/guides/language/effective-dart/style
  • 尽可能使用 const 构造函数
  • 当变量不会被重新赋值时,优先使用 final 而非 var
  • 适当使用空安全特性
  • 仅在必要时且安全时使用 late 关键字

Flutter 最佳实践

  • 尽可能使用 const widget 以提高性能
  • 当不需要状态时,优先使用 StatelessWidget 而非 StatefulWidget
  • 当 widget 变得复杂时,将其提取到单独的文件中
  • 对依赖于 context 的 widget 使用 Builder 模式
  • 避免在 build 方法中使用 setState
  • 适当使用 Key 来标识 widget

状态管理

  • 根据复杂度选择适当的状态管理解决方案
  • 尽可能保持状态局部化
  • 当多个 widget 需要时,将状态提升
  • 使用 providers、bloc 或 riverpod 管理全局状态
  • 避免属性传递 - 使用状态管理解决方案代替

Widget 组织

  • 一个 widget 一个文件(除了小的、相关的 widget)
  • 使用描述性的 widget 类名
  • 将可复用的 widget 提取到单独的文件中
  • 保持 build 方法清洁和可读
  • 优先使用组合而非继承

资源与资源文件

  • 将资源放在适当的目录中(assets/lib/assets/
  • 使用从项目根目录的相对路径引用资源
  • 使用适当的图片格式(尽可能使用 WebP)
  • 添加到项目前优化图片

测试

  • 为业务逻辑编写单元测试
  • 为 UI 组件编写 widget 测试
  • 为关键用户流程编写集成测试
  • 在重要代码路径上追求良好的测试覆盖率
  • 保持测试简单和专注

文件与项目结构

命名约定

  • 文件名使用 snake_case(例如:user_profile.dart
  • 类名使用 PascalCase(例如:UserProfile
  • 变量和函数名使用 camelCase(例如:userNamegetUserData()
  • 常量使用 UPPER_SNAKE_CASE(例如:MAX_RETRY_COUNT

目录结构

  • 将相关文件放在一起
  • 在适当时使用基于功能的组织方式
  • 分离 UI、模型、服务和工具类
  • 保持根目录整洁

文档

  • 为公共 API 编写清晰的文档注释
  • 使用 /// 进行文档注释
  • 记录复杂的算法和业务逻辑
  • 保持 README.md 更新
  • 在 CHANGELOG.md 中记录破坏性更改

Git 与版本控制

提交信息规范

提交信息格式

提交信息应遵循以下格式:

<类型>(<范围>): <主题>

<正文>

<脚注>
提交类型(Type)

使用以下类型标识提交的性质:

  • feat: 新功能
  • fix: 修复 bug
  • docs: 文档变更
  • style: 代码格式调整(不影响代码运行)
  • refactor: 代码重构(既不是新功能也不是 bug 修复)
  • perf: 性能优化
  • test: 添加或修改测试
  • chore: 构建过程或辅助工具的变动
  • ci: CI 配置文件和脚本的变更
  • build: 构建系统或外部依赖的变更
  • revert: 回滚之前的提交

Read the full file on GitHub · 342 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 342 lines · 3,061 tokens per session scan A 63baeb05bada

Subscribe to this mod's changes

main is a cursor rule published in the GitHub repository BellMemo/bell-memo-android (4 stars, last pushed 8mo ago), licensed MIT. It adds 3,061 tokens to every session, about $0.0153 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.