2026-03-02 15:05:10 +08:00
# Flutter Mobile Development Constraints
2026-02-05 15:13:06 +08:00
2026-03-02 15:05:10 +08:00
This document defines **hard constraints ** for Flutter mobile development. Treat all items as **non-negotiable ** unless explicitly overridden.
2026-02-24 18:18:42 +08:00
2026-03-12 16:41:45 +08:00
## 0) Scope and Precedence (MUST)
- This file applies to all changes under `apps/**` .
- It extends root routing rules in `AGENTS.md` and workspace global runtime rules.
- If rules conflict, apply the stricter requirement.
- Keep Flutter-specific constraints in this file; avoid duplicating them in root `AGENTS.md` .
2026-03-02 15:05:10 +08:00
## 1) Design Tokens (MUST)
2026-02-24 18:18:42 +08:00
2026-03-02 15:05:10 +08:00
- **MUST** use design tokens from `apps/lib/core/theme/design_tokens.dart` :
- Colors: `AppColors.*`
- Spacing: `AppSpacing.*`
- Radius: `AppRadius.*`
- **MUST NOT** hardcode any visual values, including (but not limited to): colors, font sizes, spacing, padding/margins, widths/heights, radii, shadows, opacity, or “magic numbers”.
- Examples that are **NOT allowed ** : `Color(0xFF...)` , `SizedBox(height: 12)` , `EdgeInsets.all(16)` , `Radius.circular(8)` .
2026-02-24 18:18:42 +08:00
2026-03-02 15:05:10 +08:00
## 2) Component Reuse (MUST)
2026-02-27 15:22:42 +08:00
2026-03-02 15:05:10 +08:00
- **MUST** prefer existing components and established page patterns over creating new UI components.
- **MUST** use:
- Buttons: `AppButton` from `apps/lib/shared/widgets/app_button.dart`
- **MUST NOT** introduce parallel UI systems (custom buttons, custom loading systems, custom input wrappers) unless explicitly required and approved.
2026-02-27 15:22:42 +08:00
2026-03-02 15:05:10 +08:00
## 3) Layout Mapping & Alignment (MUST)
2026-02-27 15:22:42 +08:00
2026-03-02 15:05:10 +08:00
- **MUST** explicitly set `crossAxisAlignment` for every `Row` / `Column` (do not rely on defaults).
- **MUST** preserve layout semantics from root to leaf:
- alignment/justification intent must be explicitly represented in Flutter widgets.
- **MUST NOT** skip necessary container layers if doing so loses layout meaning or makes mapping non-traceable.
2026-02-27 15:22:42 +08:00
2026-03-02 15:05:10 +08:00
## 4) Centering & Visual Balance (MUST)
2026-02-27 15:22:42 +08:00
2026-03-02 15:05:10 +08:00
- **MUST** evaluate centering within `SafeArea` usable bounds (not full-screen bounds).
- **MUST NOT** rely on `Spacer` / proportional flex as the only centering mechanism for critical content.
- If persistent header/footer regions exist, **MUST ** center primary content within the remaining usable region.
- **MUST** prioritize * visual centering * over purely geometric centering when they differ.
2026-02-27 15:22:42 +08:00
2026-03-12 16:41:45 +08:00
## 5) Testing Strategy (MUST)
Follow lightweight testing strategy - prioritize value over coverage:
2026-02-27 15:22:42 +08:00
2026-03-12 16:41:45 +08:00
**Write tests for: **
- Model / DTO parsing (json → model)
- Service layer logic (business rules, API call handling)
- Complex custom widgets with rich interactions
2026-02-27 15:22:42 +08:00
2026-03-12 16:41:45 +08:00
**Skip for: **
- Simple UI pages, regular buttons, basic layouts
2026-02-27 15:22:42 +08:00
2026-03-02 15:05:10 +08:00
## 6) UI Feedback System (MUST)
2026-02-24 18:18:42 +08:00
2026-03-02 15:05:10 +08:00
- All user-facing feedback **MUST ** use the Toast system.
- Transient notifications: `Toast.show(...)`
- Persistent inline form errors: `AppBanner`
- **MUST NOT** create custom SnackBar/Dialog/Banner feedback components.
- **MUST NOT** use raw `ScaffoldMessenger` for feedback messaging.
2026-02-24 18:18:42 +08:00
2026-03-02 15:05:10 +08:00
## 7) Agent Chat (AG-UI Protocol) (MUST)
2026-02-24 18:18:42 +08:00
2026-03-02 17:02:09 +08:00
Agent chat functionality **MUST ** follow the AG-UI protocol. **Use the `ag-ui` skill ** for protocol reference and implementation guidance.
2026-02-24 18:18:42 +08:00
2026-03-02 15:05:10 +08:00
- **MUST** use Server-Sent Events (SSE) for streaming.
- **MUST** emit required lifecycle events:
- `RUN_STARTED` is required for every run
- End with exactly one of: `RUN_FINISHED` or `RUN_ERROR`
- **MUST** follow standard text streaming flow:
- `TEXT_MESSAGE_START` → `TEXT_MESSAGE_CONTENT` (delta) → `TEXT_MESSAGE_END`
- **MUST** support the standard AG-UI event type set as defined in the spec.
- **MUST NOT** return non-streaming responses for agent chat.
- **MUST NOT** omit required lifecycle events.
- **MUST NOT** use non-AG-UI event formats (except where the spec explicitly allows).