Files
worker/lib/features/account/presentation/widgets/address_card.dart
Phuoc Nguyen fc4711a18e fix
2025-11-18 17:59:27 +07:00

244 lines
7.8 KiB
Dart

/// Address Card Widget
///
/// Displays a saved address with edit/delete actions.
library;
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:worker/core/constants/ui_constants.dart';
import 'package:worker/core/theme/colors.dart';
/// Address Card Widget
///
/// Shows address details with name, phone, address text, default badge,
/// and action buttons (edit/delete).
/// Supports selection mode with radio button.
class AddressCard extends StatelessWidget {
final String name;
final String phone;
final String address;
final bool isDefault;
final VoidCallback? onEdit;
final VoidCallback? onDelete;
final VoidCallback? onSetDefault;
final bool showRadio;
final bool isSelected;
final VoidCallback? onRadioTap;
const AddressCard({
super.key,
required this.name,
required this.phone,
required this.address,
this.isDefault = false,
this.onEdit,
this.onDelete,
this.onSetDefault,
this.showRadio = false,
this.isSelected = false,
this.onRadioTap,
});
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(AppRadius.card),
border: isDefault
? Border.all(color: AppColors.primaryBlue, width: 2)
: null,
boxShadow: isDefault
? [
BoxShadow(
color: AppColors.primaryBlue.withValues(alpha: 0.15),
blurRadius: 12,
offset: const Offset(0, 4),
),
]
: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.05),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Radio Button (Selection Mode)
if (showRadio)
GestureDetector(
onTap: onRadioTap,
child: Padding(
padding: const EdgeInsets.only(right: 12, top: 2),
child: Radio<bool>(
value: true,
groupValue: isSelected,
onChanged: (_) => onRadioTap?.call(),
activeColor: AppColors.primaryBlue,
),
),
),
// Address Content
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Header (Name + Badge or Set Default Button)
Row(
children: [
Flexible(
child: Text(
name,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
color: Color(0xFF212121),
),
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(width: 8),
if (isDefault)
Container(
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 2,
),
decoration: BoxDecoration(
color: AppColors.primaryBlue,
borderRadius: BorderRadius.circular(4),
),
child: const Text(
'Mặc định',
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w500,
color: Colors.white,
),
),
)
else if (onSetDefault != null)
InkWell(
onTap: onSetDefault,
borderRadius: BorderRadius.circular(4),
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 4,
),
decoration: BoxDecoration(
border: Border.all(
color: AppColors.primaryBlue.withValues(
alpha: 0.3,
),
),
borderRadius: BorderRadius.circular(4),
),
child: const Text(
'Đặt mặc định',
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w500,
color: AppColors.primaryBlue,
),
),
),
),
],
),
const SizedBox(height: 4),
// Phone
Text(
phone,
style: const TextStyle(
fontSize: 14,
color: AppColors.grey500,
),
),
const SizedBox(height: 8),
// Address Text
Text(
address,
style: const TextStyle(
fontSize: 14,
color: Color(0xFF212121),
height: 1.4,
),
),
],
),
),
const SizedBox(width: 12),
// Actions
Column(
children: [
// Edit Button
if (onEdit != null)
Material(
color: Colors.transparent,
child: InkWell(
onTap: onEdit,
borderRadius: BorderRadius.circular(8),
child: Container(
width: 36,
height: 36,
decoration: BoxDecoration(
border: Border.all(color: const Color(0xFFE2E8F0)),
borderRadius: BorderRadius.circular(8),
),
child: const Center(
child: FaIcon(
FontAwesomeIcons.penToSquare,
size: 16,
color: AppColors.primaryBlue,
),
),
),
),
),
const SizedBox(height: 8),
// Delete Button
if (onDelete != null)
Material(
color: Colors.transparent,
child: InkWell(
onTap: onDelete,
borderRadius: BorderRadius.circular(8),
child: Container(
width: 36,
height: 36,
decoration: BoxDecoration(
border: Border.all(color: const Color(0xFFE2E8F0)),
borderRadius: BorderRadius.circular(8),
),
child: const Center(
child: FaIcon(
FontAwesomeIcons.trashCan,
size: 16,
color: AppColors.danger,
),
),
),
),
),
],
),
],
),
);
}
}