200 lines
7.0 KiB
Dart
200 lines
7.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../../../core/theme/app_theme.dart';
|
|
import '../../../core/widgets/glass_container.dart';
|
|
import '../models/admin_user_model.dart';
|
|
import '../models/admin_update_user_request_dto.dart';
|
|
|
|
/// Modal dialog for editing user role or active status by Admin.
|
|
class EditUserDialog extends StatefulWidget {
|
|
final AdminUserModel user;
|
|
|
|
const EditUserDialog({super.key, required this.user});
|
|
|
|
@override
|
|
State<EditUserDialog> createState() => _EditUserDialogState();
|
|
}
|
|
|
|
class _EditUserDialogState extends State<EditUserDialog> {
|
|
late String _role;
|
|
late bool _isActive;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_role = widget.user.role.isNotEmpty ? widget.user.role : 'User';
|
|
_isActive = widget.user.isActive;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final String email = widget.user.email;
|
|
final String name = widget.user.fullName;
|
|
|
|
return Dialog(
|
|
backgroundColor: Colors.transparent,
|
|
insetPadding: const EdgeInsets.symmetric(horizontal: 20, vertical: 24),
|
|
child: GlassContainer(
|
|
borderRadius: 20,
|
|
padding: const EdgeInsets.all(24),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.all(8),
|
|
decoration: BoxDecoration(
|
|
color: AppTheme.accentCyan.withValues(alpha: 0.15),
|
|
shape: BoxShape.circle,
|
|
border: Border.all(color: AppTheme.accentCyan.withValues(alpha: 0.3)),
|
|
),
|
|
child: Icon(Icons.manage_accounts_outlined, color: AppTheme.accentCyan, size: 20),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
name.isNotEmpty ? name : 'Benutzer Bearbeiten',
|
|
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
Text(
|
|
email,
|
|
style: TextStyle(fontSize: 12, color: AppTheme.textSecondary),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 16),
|
|
const Divider(color: Colors.white10),
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
'Rolle Ändern',
|
|
style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600, color: AppTheme.textSecondary),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Row(
|
|
children: [
|
|
_RoleChip(
|
|
role: 'User',
|
|
label: 'User',
|
|
isSelected: _role == 'User',
|
|
onTap: () => setState(() => _role = 'User'),
|
|
),
|
|
const SizedBox(width: 8),
|
|
_RoleChip(
|
|
role: 'Premium',
|
|
label: 'Premium',
|
|
isSelected: _role == 'Premium',
|
|
onTap: () => setState(() => _role = 'Premium'),
|
|
),
|
|
const SizedBox(width: 8),
|
|
_RoleChip(
|
|
role: 'Admin',
|
|
label: 'Admin',
|
|
isSelected: _role == 'Admin',
|
|
onTap: () => setState(() => _role = 'Admin'),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 16),
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
|
decoration: BoxDecoration(
|
|
color: AppTheme.glassSurface,
|
|
borderRadius: BorderRadius.circular(12),
|
|
border: Border.all(color: AppTheme.glassBorder),
|
|
),
|
|
child: SwitchListTile(
|
|
contentPadding: EdgeInsets.zero,
|
|
title: const Text('Konto Status', style: TextStyle(fontWeight: FontWeight.w600, fontSize: 14)),
|
|
subtitle: Text(_isActive ? 'Aktiv (Zugriff gewährt)' : 'Gesperrt (Zugriff verweigert)',
|
|
style: TextStyle(fontSize: 12, color: _isActive ? AppTheme.primaryEmerald : AppTheme.accentRed)),
|
|
value: _isActive,
|
|
activeThumbColor: AppTheme.primaryEmerald,
|
|
onChanged: (val) => setState(() => _isActive = val),
|
|
),
|
|
),
|
|
const SizedBox(height: 24),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: Text('Abbrechen', style: TextStyle(color: AppTheme.textMuted)),
|
|
),
|
|
const SizedBox(width: 8),
|
|
ElevatedButton(
|
|
onPressed: () => Navigator.pop(context, AdminUpdateUserRequestDto(role: _role, isActive: _isActive)),
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: AppTheme.primaryEmerald,
|
|
foregroundColor: Colors.black,
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
|
),
|
|
child: const Text('Speichern', style: TextStyle(fontWeight: FontWeight.bold)),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _RoleChip extends StatelessWidget {
|
|
final String role;
|
|
final String label;
|
|
final bool isSelected;
|
|
final VoidCallback onTap;
|
|
|
|
const _RoleChip({
|
|
required this.role,
|
|
required this.label,
|
|
required this.isSelected,
|
|
required this.onTap,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final Color roleColor = role == 'Admin'
|
|
? const Color(0xFFA855F7)
|
|
: role == 'Premium'
|
|
? AppTheme.primaryEmerald
|
|
: AppTheme.accentCyan;
|
|
|
|
return Expanded(
|
|
child: InkWell(
|
|
onTap: onTap,
|
|
borderRadius: BorderRadius.circular(10),
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(vertical: 10),
|
|
alignment: Alignment.center,
|
|
decoration: BoxDecoration(
|
|
color: isSelected ? roleColor.withValues(alpha: 0.2) : AppTheme.glassSurface,
|
|
borderRadius: BorderRadius.circular(10),
|
|
border: Border.all(
|
|
color: isSelected ? roleColor : AppTheme.glassBorder,
|
|
width: isSelected ? 1.5 : 1,
|
|
),
|
|
),
|
|
child: Text(
|
|
label,
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
|
|
color: isSelected ? AppTheme.textPrimary : AppTheme.textSecondary,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|