Files
Phuoc Nguyen 49a41d24eb update theme
2025-12-02 15:20:54 +07:00

246 lines
7.9 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) {
final colorScheme = Theme.of(context).colorScheme;
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: colorScheme.surface,
borderRadius: BorderRadius.circular(AppRadius.card),
border: isDefault
? Border.all(color: colorScheme.primary, width: 2)
: null,
boxShadow: isDefault
? [
BoxShadow(
color: colorScheme.primary.withValues(alpha: 0.15),
blurRadius: 12,
offset: const Offset(0, 4),
),
]
: [
BoxShadow(
color: colorScheme.shadow.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: colorScheme.primary,
),
),
),
// Address Content
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Header (Name + Badge or Set Default Button)
Row(
children: [
Flexible(
child: Text(
name,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
color: colorScheme.onSurface,
),
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(width: 8),
if (isDefault)
Container(
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 2,
),
decoration: BoxDecoration(
color: colorScheme.primary,
borderRadius: BorderRadius.circular(4),
),
child: Text(
'Mặc định',
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w500,
color: colorScheme.onPrimary,
),
),
)
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: colorScheme.primary.withValues(
alpha: 0.3,
),
),
borderRadius: BorderRadius.circular(4),
),
child: Text(
'Đặt mặc định',
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w500,
color: colorScheme.primary,
),
),
),
),
],
),
const SizedBox(height: 4),
// Phone
Text(
phone,
style: TextStyle(
fontSize: 14,
color: colorScheme.onSurfaceVariant,
),
),
const SizedBox(height: 8),
// Address Text
Text(
address,
style: TextStyle(
fontSize: 14,
color: colorScheme.onSurface,
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: colorScheme.outlineVariant),
borderRadius: BorderRadius.circular(8),
),
child: Center(
child: FaIcon(
FontAwesomeIcons.penToSquare,
size: 16,
color: colorScheme.primary,
),
),
),
),
),
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: colorScheme.outlineVariant),
borderRadius: BorderRadius.circular(8),
),
child: const Center(
child: FaIcon(
FontAwesomeIcons.trashCan,
size: 16,
color: AppColors.danger,
),
),
),
),
),
],
),
],
),
);
}
}