109 lines
3.6 KiB
Dart
109 lines
3.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'package:pshared/models/permissions/descriptions/role.dart';
|
|
|
|
import 'package:pweb/models/state/visibility.dart';
|
|
import 'package:pweb/generated/i18n/app_localizations.dart';
|
|
|
|
|
|
class RoleCard extends StatelessWidget {
|
|
final RoleDescription role;
|
|
final int policyCount;
|
|
final VisibilityState canManagePolicies;
|
|
final VisibilityState canCopy;
|
|
final VisibilityState canDelete;
|
|
final VoidCallback onCopy;
|
|
final VoidCallback onDelete;
|
|
final VoidCallback onManagePolicies;
|
|
|
|
const RoleCard({
|
|
super.key,
|
|
required this.role,
|
|
required this.policyCount,
|
|
required this.canManagePolicies,
|
|
required this.canCopy,
|
|
required this.canDelete,
|
|
required this.onCopy,
|
|
required this.onDelete,
|
|
required this.onManagePolicies,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final loc = AppLocalizations.of(context)!;
|
|
final theme = Theme.of(context);
|
|
|
|
return Card(
|
|
elevation: 0,
|
|
color: theme.colorScheme.surfaceContainerHighest.withAlpha(40),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Icon(Icons.security_outlined),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
role.name,
|
|
style: theme.textTheme.titleMedium?.copyWith(fontWeight: FontWeight.w600),
|
|
),
|
|
if ((role.description ?? '').isNotEmpty) ...[
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
role.description!,
|
|
style: theme.textTheme.bodyMedium,
|
|
),
|
|
],
|
|
const SizedBox(height: 6),
|
|
Text(
|
|
loc.rolesPoliciesCount(policyCount),
|
|
style: theme.textTheme.bodySmall?.copyWith(
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 12),
|
|
Wrap(
|
|
spacing: 12,
|
|
children: [
|
|
if (canManagePolicies == VisibilityState.visible)
|
|
TextButton.icon(
|
|
onPressed: onManagePolicies,
|
|
icon: const Icon(Icons.tune, size: 18),
|
|
label: Text(loc.rolesPoliciesAction),
|
|
),
|
|
if (canCopy == VisibilityState.visible)
|
|
TextButton.icon(
|
|
onPressed: onCopy,
|
|
icon: const Icon(Icons.copy_outlined, size: 18),
|
|
label: Text(loc.rolesCopyAction),
|
|
),
|
|
if (canDelete == VisibilityState.visible)
|
|
TextButton.icon(
|
|
onPressed: onDelete,
|
|
icon: Icon(Icons.delete_outline, size: 18, color: theme.colorScheme.error),
|
|
label: Text(loc.delete),
|
|
style: TextButton.styleFrom(
|
|
foregroundColor: theme.colorScheme.error,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|