Files
pipelines/app/lib/features/chat/conversation/chat_permission_card.dart
T
alan 9551eceaed Complete Material-only APIs and fixtures
Remove obsolete control-family flags and icon metadata across all callers, dead alternate themes and host helpers, obsolete test setup, and the unused icon-font dependency. Preserve native Material Back transitions. Make navigation fixtures independent of update plugins and answer auxiliary shell snapshots so the complete application suite can run deterministically.
2026-11-11 21:55:39 +00:00

156 lines
4.8 KiB
Dart

import 'package:flutter/material.dart';
import '../ui/transcript/native_disclosure.dart';
import 'chat_card_styles.dart';
import 'chat_permission_card_model.dart';
/// One recorded permission request as a native card.
///
/// The headline is the request's action (or its recorded outcome), the status
/// line is the server's own note where present, and the once/always/reject
/// controls appear only while the request is still open. Every server string is
/// rendered as text, never parsed as markup.
class ChatPermissionCard extends StatelessWidget {
const ChatPermissionCard({
super.key,
required this.card,
required this.onDecision,
this.error,
});
final ChatPermissionCardData card;
final Future<void> Function(String decision) onDecision;
final String? error;
/// The card uses the shared Material card styles.
@override
Widget build(BuildContext context) => Card(
// Consecutive cards must read as separate surfaces; the row itself adds only
// the horizontal inset.
margin: const EdgeInsets.only(bottom: 12),
child: Padding(padding: const EdgeInsets.all(16), child: _body(context)),
);
Widget _body(BuildContext context) => Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsetsDirectional.only(end: 12),
child: Icon(
Icons.shield_outlined,
color: chatCardWarningColor(context),
),
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(card.headline, style: chatCardTitleStyle(context)),
Text(card.statusLine, style: chatCardSecondaryStyle(context)),
],
),
),
],
),
if (card.resourceText.isNotEmpty) ...[
const SizedBox(height: 12),
DecoratedBox(
decoration: BoxDecoration(
color: chatCardFillColor(context),
borderRadius: BorderRadius.circular(8),
),
child: Padding(
padding: const EdgeInsets.all(8),
child: Text(
card.resourceText,
maxLines: chatApprovalMaxResourceLines,
overflow: TextOverflow.ellipsis,
),
),
),
if (card.resources.join('\n') != card.resourceText)
NativeDisclosure(
label: 'Show full request',
childBuilder: (context) =>
SelectableText(card.resources.join('\n')),
),
],
if (card.showRisk && card.risk.trim().isNotEmpty) ...[
const SizedBox(height: 12),
_risk(context),
],
if (error != null && error!.trim().isNotEmpty) ...[
const SizedBox(height: 12),
Semantics(
liveRegion: true,
child: Text(
error!,
style: chatCardBodyStyle(
context,
)?.copyWith(color: chatCardErrorColor(context)),
),
),
],
if (card.actionable) ...[const SizedBox(height: 12), _controls(context)],
],
);
Widget _risk(BuildContext context) {
final tint = chatCardWarningColor(context);
return DecoratedBox(
decoration: BoxDecoration(
color: chatCardWarningFillColor(context),
borderRadius: BorderRadius.circular(8),
),
child: Padding(
padding: const EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(Icons.shield_outlined, size: 16, color: tint),
const SizedBox(width: 6),
Expanded(
child: Text(
chatRiskReviewLabel,
style: chatCardLabelStyle(context)?.copyWith(color: tint),
),
),
],
),
const SizedBox(height: 4),
Text(card.risk, style: chatCardBodyStyle(context)),
],
),
),
);
}
Widget _controls(BuildContext context) => Wrap(
spacing: 8,
runSpacing: 8,
children: [
FilledButton(
onPressed: () => onDecision(chatDecisionOnce),
child: const Text(chatApprovalOnceLabel),
),
TextButton(
onPressed: () => onDecision(chatDecisionAlways),
child: Text(card.alwaysLabel),
),
TextButton(
onPressed: () => onDecision(chatDecisionReject),
style: TextButton.styleFrom(
foregroundColor: Theme.of(context).colorScheme.error,
),
child: const Text(chatApprovalRejectLabel),
),
],
);
}