跳转到内容

组件模块

Applet 组件尽量沿用 Flutter 命名。目标是让 Flutter 开发者能识别组件、属性和 主题模型,但完全采用用 JavaScript 编写。

模块 包含内容
@app/widgets Text、图片、图标、手势、语义、装饰、变换、基础动画。
@app/layout Row/Column 辅助、stack、wrap、constraints、scroll view、sliver、自适应辅助。
@app/material Material app shell、导航、按钮、输入、弹窗、反馈、数据、主题。
@app/cupertino Cupertino app shell、导航栏、列表、picker、弹窗、输入和控件。

为了方便使用,@app/material@app/cupertino 会重新导出 core/widgets/layout API。

Scaffold({
appBar: AppBar({ title: Text("Components") }),
floatingActionButton: FloatingActionButton({
child: Icon(Icons.add),
onPressed: () => model.create(),
}),
body: ListView([
Card(
ListTile({
leading: Icon(Icons.palette),
title: Text("Color"),
subtitle: Text("Material 3 roles"),
trailing: Icon(Icons.chevron_right),
})
),
]),
});

常见 Material 分组:

  • app shell:MaterialAppScaffoldAppBarSliverAppBar
  • 导航:NavigationBarNavigationRailNavigationDrawer、tabs;
  • 操作:FilledButtonOutlinedButtonTextButtonIconButtonFloatingActionButton
  • 输入:TextFieldCheckboxRadioSwitchSliderDropdownButton、menus;
  • 反馈:dialogs、snack bars、banners、tooltips、progress indicators;
  • 数据和内容:cards、lists、chips、tables、expansion panels;
  • 主题:ThemeDataColorSchemeTheme、文本样式 token。
CupertinoPageScaffold({
navigationBar: CupertinoNavigationBar({
middle: Text("Settings"),
}),
child: CupertinoListSection([
CupertinoListTile({
title: Text("Notifications"),
trailing: CupertinoSwitch({
value: model.notifications,
onChanged: (value) => model.setNotifications(value),
}),
}),
]),
});

常见 Cupertino 分组:

  • app shell 和 page scaffold;
  • navigation bars 和 tab bars;
  • list sections 和 form rows;
  • 对话框和操作表;
  • buttons、switches、checkboxes、radios、sliders;
  • text fields、search fields、pickers、date/time pickers。

普通布局使用 Flutter 布局原语:

HStack(
Icon(Icons.info),
VStack(
Text("Title").style({ theme: "titleMedium" }),
Text("Supporting text").style({ theme: "bodyMedium" })
).gap(2).expanded()
).gap(12).cross("center");

页面级行为使用自适应辅助:

AdaptiveNavigationScaffold({
selectedIndex: model.section,
onDestinationSelected: (index) => model.selectSection(index),
destinations,
body: CurrentScreen(model),
});

Applet 应该优先提供真实 Flutter 能力,而不是近似外观实现。缺少 Flutter 组件时, 应该补充渲染器绑定或宿主扩展,不要用无关组件假装行为一致。

每个新增组件都要同步:

  • JavaScript 工厂函数和属性归一化;
  • Flutter 渲染器实现;
  • types/app.d.ts 类型声明;
  • example 覆盖;
  • 用户可见时更新文档和 changelog。