95 lines
2.7 KiB
Dart
95 lines
2.7 KiB
Dart
/// Checkout Dropdown Field Widget
|
|
///
|
|
/// Reusable dropdown field for checkout forms.
|
|
library;
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:worker/core/constants/ui_constants.dart';
|
|
import 'package:worker/core/theme/colors.dart';
|
|
|
|
/// Checkout Dropdown Field
|
|
///
|
|
/// Styled dropdown field with label and validation.
|
|
class CheckoutDropdownField extends StatelessWidget {
|
|
final String label;
|
|
final String? value;
|
|
final bool required;
|
|
final List<String> items;
|
|
final void Function(String?) onChanged;
|
|
|
|
const CheckoutDropdownField({
|
|
super.key,
|
|
required this.label,
|
|
required this.value,
|
|
required this.required,
|
|
required this.items,
|
|
required this.onChanged,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
RichText(
|
|
text: TextSpan(
|
|
text: label,
|
|
style: const TextStyle(
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w500,
|
|
color: Color(0xFF1E293B),
|
|
),
|
|
children: [
|
|
if (required)
|
|
const TextSpan(
|
|
text: ' *',
|
|
style: TextStyle(color: AppColors.danger),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
DropdownButtonFormField<String>(
|
|
initialValue: value,
|
|
decoration: InputDecoration(
|
|
filled: true,
|
|
fillColor: const Color(0xFFF8FAFC),
|
|
contentPadding: const EdgeInsets.symmetric(
|
|
horizontal: 16,
|
|
vertical: 12,
|
|
),
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(AppRadius.input),
|
|
borderSide: const BorderSide(color: Color(0xFFE2E8F0)),
|
|
),
|
|
enabledBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(AppRadius.input),
|
|
borderSide: const BorderSide(color: Color(0xFFE2E8F0)),
|
|
),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(AppRadius.input),
|
|
borderSide: const BorderSide(
|
|
color: AppColors.primaryBlue,
|
|
width: 2,
|
|
),
|
|
),
|
|
),
|
|
items: items.map((item) {
|
|
return DropdownMenuItem<String>(
|
|
value: item,
|
|
child: Text(item),
|
|
);
|
|
}).toList(),
|
|
onChanged: onChanged,
|
|
validator: (value) {
|
|
if (required && (value == null || value.isEmpty)) {
|
|
return 'Vui lòng chọn $label';
|
|
}
|
|
return null;
|
|
},
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|