import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; class NewCategoryPage extends StatefulWidget { const NewCategoryPage({Key? key}) : super(key: key); @override _NewCategoryPageState createState() => _NewCategoryPageState(); } class _NewCategoryPageState extends State { final _formKey = GlobalKey(); final _claveController = TextEditingController(); final _nombreController = TextEditingController(); DateTime _selectedDate = DateTime.now(); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Nueva Categoría'), backgroundColor: Colors.blue, ), body: Padding( padding: const EdgeInsets.all(16.0), child: Form( key: _formKey, child: Column( children: [ TextFormField( controller: _claveController, decoration: const InputDecoration(labelText: 'Clave'), validator: (value) { if (value == null || value.isEmpty) { return 'Por favor ingrese una clave'; } return null; }, ), TextFormField( controller: _nombreController, decoration: const InputDecoration(labelText: 'Nombre'), validator: (value) { if (value == null || value.isEmpty) { return 'Por favor ingrese un nombre'; } return null; }, ), const SizedBox(height: 16.0), TextFormField( readOnly: true, decoration: InputDecoration( labelText: 'Fecha de Creación', hintText: DateFormat('yyyy-MM-dd').format(_selectedDate), ), onTap: () async { DateTime? pickedDate = await showDatePicker( context: context, initialDate: _selectedDate, firstDate: DateTime(2000), lastDate: DateTime(2101), ); if (pickedDate != null && pickedDate != _selectedDate) { setState(() { _selectedDate = pickedDate; }); } }, ), const SizedBox(height: 16.0), ElevatedButton( onPressed: () { if (_formKey.currentState!.validate()) { int fechaCreado = _selectedDate.millisecondsSinceEpoch; print({ "clave": _claveController.text, "fechaCreado": fechaCreado, "nombre": _nombreController.text }); Navigator.pop(context); } }, child: const Text('GUARDAR'), style: ElevatedButton.styleFrom( foregroundColor: Colors.white, backgroundColor: Colors.blue, ), ), ], ), ), ), ); } }