after rediense
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class BirthdayPicker extends StatefulWidget {
|
||||
final Function(DateTime) onDateSelected;
|
||||
final TextEditingController controller;
|
||||
|
||||
const BirthdayPicker(
|
||||
{super.key, required this.onDateSelected, required this.controller});
|
||||
|
||||
@override
|
||||
State<BirthdayPicker> createState() => _BirthdayPickerState();
|
||||
}
|
||||
|
||||
class _BirthdayPickerState extends State<BirthdayPicker> {
|
||||
DateTime selectedDate =
|
||||
DateTime.now().subtract(const Duration(days: 365 * 20));
|
||||
|
||||
Future<void> _selectDate(BuildContext context) async {
|
||||
final DateTime? picked = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: selectedDate,
|
||||
firstDate: DateTime.now().subtract(const Duration(days: 365 * 120)),
|
||||
lastDate: DateTime.now(),
|
||||
);
|
||||
|
||||
if (picked != null && picked != selectedDate) {
|
||||
setState(() {
|
||||
selectedDate = picked;
|
||||
widget.onDateSelected(selectedDate);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TextFormField(
|
||||
onTap: () {
|
||||
_selectDate(context);
|
||||
},
|
||||
readOnly: true,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Fecha de nacimiento',
|
||||
prefixIcon: const Icon(Icons.calendar_month_rounded),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10.0),
|
||||
),
|
||||
errorBorder: OutlineInputBorder(
|
||||
borderSide: const BorderSide(color: Colors.red),
|
||||
borderRadius: BorderRadius.circular(10.0),
|
||||
),
|
||||
focusedErrorBorder: OutlineInputBorder(
|
||||
borderSide: const BorderSide(color: Colors.red, width: 2.0),
|
||||
borderRadius: BorderRadius.circular(10.0),
|
||||
),
|
||||
),
|
||||
controller: widget.controller,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user