7d2c3412a1
Adds the Paper design and generalises design tokens (transcript, composer, selected-row styles, reading type, panel fill, chat colour saturation). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
161 lines
4.9 KiB
Dart
161 lines
4.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../ui/transcript/native_disclosure.dart';
|
|
import 'chat_card_styles.dart';
|
|
import 'chat_permission_card_model.dart';
|
|
import '../../../ui/theme/app_design_tokens.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: AppDesignTokens.of(
|
|
context,
|
|
).corners(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: AppDesignTokens.of(
|
|
context,
|
|
).corners(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),
|
|
),
|
|
],
|
|
);
|
|
}
|