Sfoglia il codice sorgente

First commint on BRNDEV

c90Beretta 3 mesi fa
parent
commit
e312f19935
2 ha cambiato i file con 124 aggiunte e 21 eliminazioni
  1. 55 21
      lib/views/home/home_view.dart
  2. 69 0
      lib/views/home/tarea_view_form.dart

+ 55 - 21
lib/views/home/home_view.dart

@@ -8,6 +8,7 @@ import 'package:sis_flutter/services/usuario_session_service.dart';
 import 'package:sis_flutter/viewmodels/login_view_model.dart';
 import 'package:sis_flutter/viewmodels/actividad_view_model.dart';
 import 'package:sis_flutter/viewmodels/viewmodels.dart';
+import 'package:sis_flutter/views/home/tarea_view_form.dart';
 import 'package:sis_flutter/widgets/app_dropdown_search.dart';
 import 'package:sis_flutter/widgets/app_loader.dart';
 import 'package:url_launcher/url_launcher.dart';
@@ -93,9 +94,9 @@ class _HomeBodyState extends State<HomeBody> {
                         )),
                     Text(_usuario?.name! ?? "Cargando...",
                         style: const TextStyle(
-                            fontSize: 45,
-                            fontWeight: FontWeight.bold,
-                            height: -1)),
+                          fontSize: 45,
+                          fontWeight: FontWeight.bold,
+                        )),
                     const SizedBox(height: 10),
                     Container(
                         decoration: BoxDecoration(
@@ -138,6 +139,19 @@ class _HomeBodyState extends State<HomeBody> {
 
   Card _infoCard(Actividad actividad) {
     List<Widget> tareaWidgets = [];
+
+    tareaWidgets.add(Center(
+      child: IconButton(
+        style:
+            ButtonStyle(backgroundColor: WidgetStatePropertyAll(Colors.blue)),
+        icon: const Icon(Icons.add),
+        color: Colors.white,
+        onPressed: () {
+          _showAddTaskModal(context);
+        },
+      ),
+    ));
+
     for (var tarea in actividad.tareas!) {
       // final posicion = (actividad.tareas!.indexOf(tarea) + 1).toString();
       final Color color = getPrioridadColors(tarea.prioridad!);
@@ -158,25 +172,11 @@ class _HomeBodyState extends State<HomeBody> {
               title: Linkify(
                   text: tarea.contenido!,
                   onOpen: (link) async {
-                    if (await canLaunchUrlString(link.url)) {
-                      await launchUrlString(link.url);
-                    } else {
-                      throw CupertinoAlertDialog(
-                        title: const Text("Error"),
-                        content: const Text("No se puede abrir el link"),
-                        actions: [
-                          CupertinoDialogAction(
-                            child: const Text("OK"),
-                            onPressed: () {
-                              Navigator.of(context).pop();
-                            },
-                          )
-                        ],
-                      );
-                    }
+                    linkfyDialog(link);
                   }),
-                  subtitle: Text(tarea.urgencia!),
-
+              subtitle: Text(tarea.urgencia!),
+              trailing:
+                  IconButton(onPressed: () {}, icon: const Icon(Icons.edit)),
             ),
           ],
         ),
@@ -231,6 +231,25 @@ class _HomeBodyState extends State<HomeBody> {
     );
   }
 
+  linkfyDialog(link) async {
+    if (await canLaunchUrlString(link.url)) {
+      await launchUrlString(link.url);
+    } else {
+      throw CupertinoAlertDialog(
+        title: const Text("Error"),
+        content: const Text("No se puede abrir el link"),
+        actions: [
+          CupertinoDialogAction(
+            child: const Text("OK"),
+            onPressed: () {
+              Navigator.of(context).pop();
+            },
+          )
+        ],
+      );
+    }
+  }
+
   Color getPrioridadColors(tarea) {
     return tarea == 1
         ? Colors.red
@@ -243,3 +262,18 @@ class _HomeBodyState extends State<HomeBody> {
                     : Colors.grey;
   }
 }
+
+void _showAddTaskModal(BuildContext context) {
+  showModalBottomSheet(
+    context: context,
+    isScrollControlled: true,
+    builder: (BuildContext context) {
+      return Padding(
+        padding: EdgeInsets.only(
+          bottom: MediaQuery.of(context).viewInsets.bottom,
+        ),
+        child: NewTareaForm(),
+      );
+    },
+  );
+}

+ 69 - 0
lib/views/home/tarea_view_form.dart

@@ -0,0 +1,69 @@
+import 'package:flutter/material.dart';
+
+class NewTareaForm extends StatefulWidget {
+  const NewTareaForm({super.key});
+
+  @override
+  _NewTareaFormState createState() => _NewTareaFormState();
+}
+
+class _NewTareaFormState extends State<NewTareaForm> {
+  final _formKey = GlobalKey<FormState>();
+  String _taskName = '';
+
+  void _submitForm() {
+    if (_formKey.currentState!.validate()) {
+      _formKey.currentState!.save();
+      
+      Navigator.of(context).pop();
+    }
+  }
+
+  @override
+  Widget build(BuildContext context) {
+    return Padding(
+      padding: const EdgeInsets.all(16.0),
+      child: Form(
+        key: _formKey,
+        child: Column(
+          mainAxisSize: MainAxisSize.min,
+          children: [
+            Form(
+              key: _formKey,
+              child: TextFormField(
+                decoration: InputDecoration(labelText: 'Ingrese La nueva tarea'),
+                validator: (value) {
+                  if (value == null || value.isEmpty) {
+                    return 'Porfavor ingrese una tarea';
+                  }
+                  return null;
+                },
+                onSaved: (value) {
+                  _taskName = value!;
+                },
+              ),
+            ),
+            SizedBox(height: 16),
+            TextFormField(
+              decoration: InputDecoration(labelText: 'Ingrese la prioridad'),
+              validator: (value) {
+                if (value == null || value.isEmpty) {
+                  return 'Porfavor ingrese una prioridad';
+                }
+                return null;
+              },
+              onSaved: (value) {
+                _taskName = value!;
+              },
+            ),
+            SizedBox(height: 16),
+            ElevatedButton(
+              onPressed: _submitForm,
+              child: Text('Nueva Tarea'),
+            ),
+          ],
+        ),
+      ),
+    );
+  }
+}