flutter-ui
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese1. Performance & Rendering
1. 性能与渲染
- Const-First: Every widget that can be MUST be
const.const - Lazy Rendering: Use or
SliverList.builderfor lists > 10 items.SliverGrid.builder - Repaint Boundaries: Wrap complex animations in .
RepaintBoundary - Isolate Parsing: Use or
compute()for JSON > 1MB.Isolate - BuildContext Safety: Check before using
mountedacross async gaps.context
- 优先使用Const:所有可以声明为的widget都必须声明为
const。const - 懒渲染:针对超过10项的列表,使用或
SliverList.builder。SliverGrid.builder - 重绘边界:将复杂动画包裹在中。
RepaintBoundary - 隔离解析:针对大于1MB的JSON,使用或
compute()处理。Isolate - BuildContext安全:在异步间隙使用前,需检查
context状态。mounted
2. Design Tokens (Theming)
2. 设计令牌(主题配置)
Use , , , and . NEVER hardcode raw values.
AppColorsAppSpacingAppRadiusAppTypography- Colors: Use or
context.colorScheme.primary. Support light/dark modes.AppColors - Spacing: Use (8),
AppSpacing.sm(16), etc. UseAppSpacing.mdfor gaps.SizedBox - Radius: Use (12) for consistent rounding.
AppRadius.md - Typography: Use . Support text scaling.
context.textTheme.bodyMedium
使用、、和,严禁硬编码原始值。
AppColorsAppSpacingAppRadiusAppTypography- 颜色:使用或
context.colorScheme.primary,支持亮/暗模式。AppColors - 间距:使用(8)、
AppSpacing.sm(16)等,用AppSpacing.md实现间隙。SizedBox - 圆角:使用(12)保证圆角风格统一。
AppRadius.md - 字体:使用,支持文本缩放。
context.textTheme.bodyMedium
3. Reusable Components
3. 可复用组件
- Single Responsibility: Each component has one clear purpose.
- Parameterization: Expose parameters for customization.
- Complexity: Extract widgets or code blocks used multiple times into .
core/views/widgets - Keys: Assign to interactive widgets for test access.
Key('feature_action_id')
- 单一职责:每个组件仅有一个明确的用途。
- 参数化:对外暴露参数支持自定义。
- 复杂度控制:将多次使用的widget或代码块提取到目录下。
core/views/widgets - 键值:为可交互组件分配,便于测试时定位。
Key('feature_action_id')
4. Widget & Interaction Patterns
4. Widget与交互模式
- Extraction: STRICTLY prohibit private methods. Extract into separate widget classes.
_build*() - Slivers: Prefer with Slivers for non-trivial scrollable layouts.
CustomScrollView - FAB: Use Floating Action Buttons for primary positive actions (Add, Create).
- Scroll Padding: Add dynamic bottom padding when a FAB or BottomBar is present to prevent overlap.
- Sheets vs Screens: Prefer full screens over
Scaffoldfor complex forms.ModalBottomSheet
- 抽取规则:严格禁止定义私有方法,将其抽取为独立的widget类。
_build*() - Slivers:针对非简单滚动布局,优先使用搭配Slivers的。
CustomScrollView - 悬浮按钮:主正向操作(添加、创建)使用悬浮操作按钮(Floating Action Button)。
- 滚动内边距:存在悬浮按钮或底部导航栏时,添加动态底部内边距避免内容被遮挡。
- 底页 vs 页面:复杂表单优先使用完整的页面,而非
Scaffold。ModalBottomSheet
5. Adaptive & Responsive Design
5. 自适应与响应式设计
- Mobile First: Design for mobile, then adapt for tablet () and desktop (
600-840).>840 - Measure & Branch: Use for layout decisions;
MediaQuery.sizeOf(context)for widget constraints.LayoutBuilder - Rules: Never lock orientation. Support keyboard navigation and hover effects.
- 移动端优先:先针对移动端设计,再适配平板()和桌面端(
600-840)。>840 - 测量与分支:使用做布局决策,使用
MediaQuery.sizeOf(context)获取widget约束。LayoutBuilder - 规则:切勿锁定屏幕方向,支持键盘导航和悬停效果。
6. UI States & Accessibility
6. UI状态与无障碍
- States: Always handle Loading, Error, and Empty states with clear messaging.
- Accessibility: Include labels. Ensure 48x48 dp touch targets. WCAG AA contrast.
Semantics
- 状态处理:始终处理加载、错误、空状态,搭配清晰的提示信息。
- 无障碍支持:添加标签,保证触摸目标尺寸为48x48 dp,满足WCAG AA对比度要求。
Semantics