到目前为止服务端答的是值。现在它答 一块画面。
画面就是一个文件
{ "type": "page", "title": "Desk",
"content": { "type": "center",
"child": { "type": "linear", "direction": "vertical", "spacing": 14, "alignment": "center", "children": [
{ "type": "text", "text": "WAITING", "style": { "fontSize": 16, "letterSpacing": 4, "color": "#6b7280" } },
{ "type": "text", "text": "{{waiting}}", "style": { "fontSize": 88, "fontWeight": "bold", "color": "#111827" } },
{ "type": "button", "label": "Admit one", "onTap": { "type": "tool", "tool": "desk.admit", "params": { "count": 1 } } } ] } } }
六行。值落在 {{waiting}} 的位置,按钮调用第三篇做的那个工具。
服务端把它交出来
server.addResource(
uri: 'ui://desk',
name: 'Desk screen',
description: 'The desk screen, served as a document',
mimeType: 'application/json',
handler: (uri, params) async => ReadResourceResult(contents: [
ResourceContentInfo(
uri: 'ui://desk',
mimeType: 'application/json',
text: File(_screenPath).readAsStringSync(),
)
]),
);
ResourcesCapability 也要打开。
capabilities: ServerCapabilities(
tools: ToolsCapability(listChanged: true),
resources: ResourcesCapability(listChanged: true),
),