tarea_view_form.dart 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import 'package:flutter/material.dart';
  2. class NewTareaForm extends StatefulWidget {
  3. const NewTareaForm({super.key});
  4. @override
  5. _NewTareaFormState createState() => _NewTareaFormState();
  6. }
  7. class _NewTareaFormState extends State<NewTareaForm> {
  8. final _formKey = GlobalKey<FormState>();
  9. String _taskName = '';
  10. void _submitForm() {
  11. if (_formKey.currentState!.validate()) {
  12. _formKey.currentState!.save();
  13. Navigator.of(context).pop();
  14. }
  15. }
  16. @override
  17. Widget build(BuildContext context) {
  18. return Padding(
  19. padding: const EdgeInsets.all(16.0),
  20. child: Form(
  21. key: _formKey,
  22. child: Column(
  23. mainAxisSize: MainAxisSize.min,
  24. children: [
  25. Form(
  26. key: _formKey,
  27. child: TextFormField(
  28. decoration: InputDecoration(labelText: 'Ingrese La nueva tarea'),
  29. validator: (value) {
  30. if (value == null || value.isEmpty) {
  31. return 'Porfavor ingrese una tarea';
  32. }
  33. return null;
  34. },
  35. onSaved: (value) {
  36. _taskName = value!;
  37. },
  38. ),
  39. ),
  40. SizedBox(height: 16),
  41. TextFormField(
  42. decoration: InputDecoration(labelText: 'Ingrese la prioridad'),
  43. validator: (value) {
  44. if (value == null || value.isEmpty) {
  45. return 'Porfavor ingrese una prioridad';
  46. }
  47. return null;
  48. },
  49. onSaved: (value) {
  50. _taskName = value!;
  51. },
  52. ),
  53. SizedBox(height: 16),
  54. ElevatedButton(
  55. onPressed: _submitForm,
  56. child: Text('Nueva Tarea'),
  57. ),
  58. ],
  59. ),
  60. ),
  61. );
  62. }
  63. }