import 'package:flutter/material.dart'; import '../../features/chat/ui/transcript/chat_markdown_view.dart'; /// Authored markdown (a pipeline's source, a stage's prompt) shown rendered, /// with a switch to the raw text. class MarkdownSourceView extends StatefulWidget { const MarkdownSourceView({super.key, required this.text, required this.raw}); final String text; /// The exact text as the screen already showed it. final Widget raw; @override State createState() => _MarkdownSourceViewState(); } class _MarkdownSourceViewState extends State { // Raw first: the exact text the screen always showed. bool _raw = true; void _set(bool raw) => setState(() => _raw = raw); @override Widget build(BuildContext context) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ MarkdownModeSwitch(raw: _raw, onChanged: _set), const SizedBox(height: 8), if (_raw) widget.raw else ChatMarkdownView(text: widget.text), ], ); } } /// The Rendered | Raw switch for markdown text; one switch can govern a /// whole page of fields. class MarkdownModeSwitch extends StatelessWidget { const MarkdownModeSwitch({ super.key, required this.raw, required this.onChanged, }); final bool raw; final ValueChanged onChanged; @override Widget build(BuildContext context) { return SegmentedButton( key: const Key('markdown-source-mode'), showSelectedIcon: false, segments: const [ ButtonSegment(value: false, label: Text('Rendered')), ButtonSegment(value: true, label: Text('Raw')), ], selected: {raw}, onSelectionChanged: (value) => onChanged(value.single), ); } }