import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:sis_flutter/models/tarea_model.dart'; import 'package:sis_flutter/viewmodels/login_view_model.dart'; import 'package:sis_flutter/viewmodels/tarea_view_mode.dart'; import 'package:sis_flutter/widgets/app_drawer.dart'; import 'package:sis_flutter/widgets/widgets_components.dart'; class HomeScreen extends StatefulWidget { static const String route = '/home'; const HomeScreen({super.key}); @override Formulario createState() => Formulario(); } class Formulario extends State { DateTime? fechaInicio = DateTime.now(); DateTime? fechaFin; ScrollController horizontalScrollController = ScrollController(); ScrollController verticalScrollController = ScrollController(); @override void initState() { super.initState(); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.grey.shade200, drawer: AppDrawer(), appBar: encabezado( acciones: [ IconButton( onPressed: () {}, icon: const Icon(Icons.restart_alt_rounded)), ], titulo: 'Inicio', ), body: const Bodytest(), ); } } class Bodytest extends StatefulWidget { const Bodytest({ super.key, }); @override State createState() => _BodytestState(); } class _BodytestState extends State { @override void initState() { super.initState(); Future( () async { final idusuario = Provider.of(context, listen: false).idUsuario; Provider.of(context, listen: false) .fetchPriodidades(idusuario); Provider.of(context, listen: false) .fetchDetalle(idusuario); }, ); } @override void dispose() { super.dispose(); } @override Widget build(BuildContext context) { var vm = Provider.of(context); var prioridades = vm.prioridades; var detalles = vm.detalle; return SingleChildScrollView( child: Column( mainAxisAlignment: MainAxisAlignment.start, children: [ SizedBox( height: 500, child: ListView.builder( itemCount: detalles.length, itemBuilder: (context, index) { var detalle = detalles[index]; var prioridad = prioridades[index]; return _infoCard(prioridad, detalle); })), ], ), ); } Card _infoCard(Tarea prioridad, Detalle detalle) { print(detalle); print(detalle.nombreProyecto); print(detalle.nombre); return Card( margin: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 8), elevation: 4, shape: BeveledRectangleBorder(borderRadius: BorderRadius.circular(6.0)), child: ExpansionTile( backgroundColor: Colors.white24, leading: const Icon(Icons.local_fire_department_rounded), title: Text( //!detalle nombre "${detalle.nombreProyecto!} - ${detalle.nombre!}", style: const TextStyle(fontSize: 20), strutStyle: const StrutStyle(fontWeight: FontWeight.bold), ), trailing: const Icon(Icons.arrow_drop_down), subtitle: Row( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.center, children: [ Text(detalle.avance!), const SizedBox( width: 10), // AƱadir espacio entre el texto y el indicador de progreso Expanded( child: ClipRRect( borderRadius: BorderRadius.all(Radius.circular(10)), child: LinearProgressIndicator( value: double.parse(detalle.avance!) / 100, backgroundColor: Colors.grey, valueColor: AlwaysStoppedAnimation( _calcularColorPorcentaje(detalle.avance!), ), ), ), ), ], ), children: [ ListTile( title: Text(prioridad.id), subtitle: Text("Subtarea 1"), ), ListTile( title: Text("Tarea 2"), subtitle: Text("Subtarea 2"), ), ], ), ); } } Color _calcularColorPorcentaje(String avance) { final porcentaje = double.parse(avance); if (porcentaje > 66) return Colors.green; if (porcentaje > 33) return Colors.orange; return Colors.red; }