flutter-ui

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

1. Performance & Rendering

1. 性能与渲染

  • Const-First: Every widget that can be
    const
    MUST be
    const
    .
  • Lazy Rendering: Use
    SliverList.builder
    or
    SliverGrid.builder
    for lists > 10 items.
  • Repaint Boundaries: Wrap complex animations in
    RepaintBoundary
    .
  • Isolate Parsing: Use
    compute()
    or
    Isolate
    for JSON > 1MB.
  • BuildContext Safety: Check
    mounted
    before using
    context
    across async gaps.
  • 优先使用Const:所有可以声明为
    const
    的widget都必须声明为
    const
  • 懒渲染:针对超过10项的列表,使用
    SliverList.builder
    SliverGrid.builder
  • 重绘边界:将复杂动画包裹在
    RepaintBoundary
    中。
  • 隔离解析:针对大于1MB的JSON,使用
    compute()
    Isolate
    处理。
  • BuildContext安全:在异步间隙使用
    context
    前,需检查
    mounted
    状态。

2. Design Tokens (Theming)

2. 设计令牌(主题配置)

Use
AppColors
,
AppSpacing
,
AppRadius
, and
AppTypography
. NEVER hardcode raw values.
  • Colors: Use
    context.colorScheme.primary
    or
    AppColors
    . Support light/dark modes.
  • Spacing: Use
    AppSpacing.sm
    (8),
    AppSpacing.md
    (16), etc. Use
    SizedBox
    for gaps.
  • Radius: Use
    AppRadius.md
    (12) for consistent rounding.
  • Typography: Use
    context.textTheme.bodyMedium
    . Support text scaling.
使用
AppColors
AppSpacing
AppRadius
AppTypography
,严禁硬编码原始值。
  • 颜色:使用
    context.colorScheme.primary
    AppColors
    ,支持亮/暗模式。
  • 间距:使用
    AppSpacing.sm
    (8)、
    AppSpacing.md
    (16)等,用
    SizedBox
    实现间隙。
  • 圆角:使用
    AppRadius.md
    (12)保证圆角风格统一。
  • 字体:使用
    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
    Key('feature_action_id')
    to interactive widgets for test access.
  • 单一职责:每个组件仅有一个明确的用途。
  • 参数化:对外暴露参数支持自定义。
  • 复杂度控制:将多次使用的widget或代码块提取到
    core/views/widgets
    目录下。
  • 键值:为可交互组件分配
    Key('feature_action_id')
    ,便于测试时定位。

4. Widget & Interaction Patterns

4. Widget与交互模式

  • Extraction: STRICTLY prohibit private
    _build*()
    methods. Extract into separate widget classes.
  • Slivers: Prefer
    CustomScrollView
    with Slivers for non-trivial scrollable layouts.
  • 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
    Scaffold
    screens over
    ModalBottomSheet
    for complex forms.
  • 抽取规则:严格禁止定义私有
    _build*()
    方法,将其抽取为独立的widget类。
  • Slivers:针对非简单滚动布局,优先使用搭配Slivers的
    CustomScrollView
  • 悬浮按钮:主正向操作(添加、创建)使用悬浮操作按钮(Floating Action Button)。
  • 滚动内边距:存在悬浮按钮或底部导航栏时,添加动态底部内边距避免内容被遮挡。
  • 底页 vs 页面:复杂表单优先使用完整的
    Scaffold
    页面,而非
    ModalBottomSheet

5. Adaptive & Responsive Design

5. 自适应与响应式设计

  • Mobile First: Design for mobile, then adapt for tablet (
    600-840
    ) and desktop (
    >840
    ).
  • Measure & Branch: Use
    MediaQuery.sizeOf(context)
    for layout decisions;
    LayoutBuilder
    for widget constraints.
  • Rules: Never lock orientation. Support keyboard navigation and hover effects.
  • 移动端优先:先针对移动端设计,再适配平板(
    600-840
    )和桌面端(
    >840
    )。
  • 测量与分支:使用
    MediaQuery.sizeOf(context)
    做布局决策,使用
    LayoutBuilder
    获取widget约束。
  • 规则:切勿锁定屏幕方向,支持键盘导航和悬停效果。

6. UI States & Accessibility

6. UI状态与无障碍

  • States: Always handle Loading, Error, and Empty states with clear messaging.
  • Accessibility: Include
    Semantics
    labels. Ensure 48x48 dp touch targets. WCAG AA contrast.
  • 状态处理:始终处理加载、错误、空状态,搭配清晰的提示信息。
  • 无障碍支持:添加
    Semantics
    标签,保证触摸目标尺寸为48x48 dp,满足WCAG AA对比度要求。