Files
pipelines/app/lib/ui/text/markdown_source_view.dart
alan 3ca1bf4a00 Remove Cupertino UI branches
Keep the Material-only status, text, and scale paths while preserving public signatures and the Cupertino colors still required by the status API.
2026-11-11 01:00:35 +00:00

64 lines
1.7 KiB
Dart

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<MarkdownSourceView> createState() => _MarkdownSourceViewState();
}
class _MarkdownSourceViewState extends State<MarkdownSourceView> {
// 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<bool> onChanged;
@override
Widget build(BuildContext context) {
return SegmentedButton<bool>(
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),
);
}
}