Render agent questions as markdown

A question's text, its description and its options' descriptions now
use the transcript's markdown renderer (bold, code, lists, links) in
the card's own text styles; tapping an option's formatted description
still selects it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 15:23:24 +00:00
parent 03688f0c1f
commit 509d4c624f
5 changed files with 93 additions and 6 deletions
@@ -4,6 +4,7 @@ import 'package:flutter/services.dart';
import '../../../core/api_gateway.dart';
import 'chat_card_styles.dart';
import 'chat_question_card_model.dart';
import 'chat_question_markdown.dart';
import 'chat_composer_bar.dart' show chatEnterSends;
import 'chat_no_reveal.dart';
import 'chat_question_option_controls.dart';
@@ -63,9 +64,12 @@ Widget _field({
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: [
Text(label, style: chatCardLabelStyle(context)),
ChatQuestionMarkdown(label, style: chatCardLabelStyle(context)),
if (description.isNotEmpty && description != title)
Text(description, style: chatCardSecondaryStyle(context)),
ChatQuestionMarkdown(
description,
style: chatCardSecondaryStyle(context),
),
if ('${field['type'] ?? ''}' == 'external')
_external(context, field)
else if ('${field['type'] ?? ''}' == 'boolean')
@@ -0,0 +1,22 @@
import 'package:flutter/material.dart';
import '../ui/transcript/chat_markdown_view.dart';
/// A question's text (its title, description or an option's description)
/// rendered as markdown in [style]: agents format questions with bold, code,
/// lists and links, the same subset the transcript draws.
class ChatQuestionMarkdown extends StatelessWidget {
const ChatQuestionMarkdown(this.text, {super.key, this.style});
final String text;
final TextStyle? style;
@override
Widget build(BuildContext context) {
final view = ChatMarkdownView(text: text);
final style = this.style;
return style == null
? view
: DefaultTextStyle.merge(style: style, child: view);
}
}
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import 'chat_question_card_model.dart';
import 'chat_question_markdown.dart';
/// Native option controls for one question field. Single-select uses the host's
/// radio/checklist pattern, multi-select toggles choices, and `onChanged`
@@ -30,7 +31,7 @@ Widget chatQuestionOptionsField({
title: Text(chatQuestionOptionLabel(option)),
subtitle: '${option['description'] ?? ''}'.trim().isEmpty
? null
: Text('${option['description']}'.trim()),
: ChatQuestionMarkdown('${option['description']}'.trim()),
contentPadding: EdgeInsets.zero,
controlAffinity: ListTileControlAffinity.leading,
onChanged: (on) => onChanged(
@@ -53,7 +54,7 @@ Widget chatQuestionOptionsField({
title: Text(chatQuestionOptionLabel(option)),
subtitle: '${option['description'] ?? ''}'.trim().isEmpty
? null
: Text('${option['description']}'.trim()),
: ChatQuestionMarkdown('${option['description']}'.trim()),
contentPadding: EdgeInsets.zero,
controlAffinity: ListTileControlAffinity.leading,
),