Tengo un menú principal, que contiene un listview que carga cinco registros de un empleado (cuyos datos son RecordDate
, EntryTime
, ExitTime
y quiero obtener el RecordDate
de alguno de esos , y usar ese dato, para enviarlo en una ruta http, y que me devuelva la información completa de esa fecha en otra pantalla, ya tengo el método que convierte la fecha que me devuelve la base de datos, a lo que necesito para llamar el registro completo.
El siguiente, es el código de la lista que genera los cinco registros que aparecen en pantalla:
FutureBuilder<List<Record>>(
future: futureRecord,
builder: (context, snapshot) {
if (snapshot.hasData) {
//LIST BUILDER QUE CARGA LOS CINCO REGISTROS RECIENTES
return ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: snapshot.data!.length,
itemBuilder: (_, index) => GestureDetector(
onTap: () => Navigator.pushNamed(context, '/DisplayRecordScreenUser', arguments: convertirFechaArgumento(snapshot.data![index].RecordDate), ),
child: Container(
margin: const EdgeInsets.symmetric(
horizontal: 8, vertical: 2),
padding: const EdgeInsets.all(18.0),
decoration: BoxDecoration(
color: const Color.fromARGB(255, 255, 255, 255),
borderRadius: BorderRadius.circular(8.0),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
convertirFecha(
snapshot.data![index].RecordDate),
style: const TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.bold,
),
),
const Icon(
Icons.arrow_upward_outlined,
color: Colors.green,
),
Text(
convertirHora(
snapshot.data![index].EntryTime),
style: const TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.bold,
),
),
const Icon(
Icons.arrow_downward_outlined,
color: Colors.red,
),
Text(
convertirHora(snapshot.data![index].ExitTime),
style: const TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.bold,
),
),
],
),
),
));
} else {
return const Center(child: CircularProgressIndicator());
}
},
),
El siguiente código, es de la vista donde quiero cargar el registro con la fecha enviada por argumento, el problema es que me arroja el siguiente error:
FlutterError (dependOnInheritedWidgetOfExactType<_ModalScopeStatus>() or dependOnInheritedElement() was called before _DisplayRecordScreenUserState.initState() completed.
When an inherited widget changes, for example if the value of Theme.of() changes, its dependent widgets are rebuilt. If the dependent widget's reference to the inherited widget is in a constructor or an initState() method, then the rebuilt dependent widget will not reflect the changes in the inherited widget.
Typically references to inherited widgets should occur in widget build() methods. Alternatively, initialization based on inherited widgets can be placed in the didChangeDependencies method, which is called after initState and whenever the dependencies change thereafter.)
class _DisplayRecordScreenUserState extends State<DisplayRecordScreenUser> {
late Future<FullRecord> futureRecord;
@override
void initState() {
super.initState();
futureRecord = fetchFullRecord();
}
Future<FullRecord> fetchFullRecord() async {
final args = await ModalRoute.of(context)!.settings.arguments;
print(args);
//http request GET
final response = await http.get(Uri.parse('https://ecdf-45-65-152-57.ngrok.io/get/fulluserrecord/1/$args'));
if (response.statusCode == 200) {
return FullRecord.fromJson(jsonDecode(response.body)[0]);
//El [0], es para ignorar que el json no tiene una cabecera tipo RECORD.
} else {
throw Exception('Failed to load record.');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppTheme.background,
appBar:
//APP BAR
AppBar(
title: const Text('displayrecords.displayRecord').tr(),
centerTitle: true,
actions: [
IconButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const EditRecordScreenUser()));
},
icon: const Icon(Icons.edit_outlined))
]),
body: FutureBuilder<FullRecord>(
future: futureRecord,
builder: (context, snapshot) {
if (snapshot.hasData) {
return Container(
color: Colors.white,
child: Column(
children: [
//ListTile que muestra la fecha y texto Record Date del registro consultado.
ListTile(
title: Text((convertirFecha(snapshot.data!.date)),
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 24)),
subtitle: Text('displayrecords.recordDate'.tr(), textAlign: TextAlign.center,),
),
ListTile(
title: Text("displayrecords.TRattendance".tr()),
trailing: Wrap(
spacing: 12, // Espacio entre dos íconos
children: <Widget>[
const Icon(Icons.arrow_upward_outlined, color: AppTheme.green,), // icon-1
Text(convertirHora(snapshot.data!.entryTime1), style: const TextStyle(fontSize: 18),),
const Icon(Icons.arrow_downward_outlined, color: AppTheme.red,), // icon-2
Text(convertirHora(snapshot.data!.exitTime1), style: const TextStyle(fontSize: 18),)
],
),
)
} else {
return const CircularProgressIndicator();
}
// By default, show a loading spinner.
},
)
);
}