96de9f5bea
Keep the Material-only conversation implementation while preserving public Cupertino parameters for callers. Narrow affected tests to Material hosts so the dead platform paths are no longer exercised.
164 lines
5.1 KiB
Dart
164 lines
5.1 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-style helpers keep their `cupertino` flag for existing callers;
|
|
/// the card is always Material, so every call passes `false`.
|
|
@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, false),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(card.headline, style: chatCardTitleStyle(context, false)),
|
|
Text(
|
|
card.statusLine,
|
|
style: chatCardSecondaryStyle(context, false),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
if (card.resourceText.isNotEmpty) ...[
|
|
const SizedBox(height: 12),
|
|
DecoratedBox(
|
|
decoration: BoxDecoration(
|
|
color: chatCardFillColor(context, false),
|
|
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,
|
|
false,
|
|
)?.copyWith(color: chatCardErrorColor(context, false)),
|
|
),
|
|
),
|
|
],
|
|
if (card.actionable) ...[const SizedBox(height: 12), _controls(context)],
|
|
],
|
|
);
|
|
|
|
Widget _risk(BuildContext context) {
|
|
final tint = chatCardWarningColor(context, false);
|
|
return DecoratedBox(
|
|
decoration: BoxDecoration(
|
|
color: chatCardWarningFillColor(context, false),
|
|
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,
|
|
false,
|
|
)?.copyWith(color: tint),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(card.risk, style: chatCardBodyStyle(context, false)),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
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),
|
|
),
|
|
],
|
|
);
|
|
}
|