here is my class model
do not pay attention to hivefield and hivetype
I know how to read the data from my Patient list but not from ListNote which is in my Patient list
import 'package:hive_flutter/hive_flutter.dart';
part 'listpatient.g.dart';
@HiveType(typeId: 0)
class Patients {
@HiveField(0)
final String? name;
@HiveField(1)
final String? firstname;
@HiveField(3)
final String? dateofbirth;
@HiveField(4)
final String? email;
@HiveField(5)
final String? numero;
@HiveField(6)
final DateTime? date;
@HiveField(7)
final int? id;
@HiveField(8)
final List<ListNote>? listOfNotes;
const Patients({
this.name,
this.firstname,
this.dateofbirth,
this.email,
this.numero,
this.date,
this.id,
this.listOfNotes,
});
}
@HiveType(typeId: 0)
class ListNote {
@HiveField(1)
final String? title;
@HiveField(2)
final String? note;
@HiveField(3)
final String? conclusion;
ListNote({
this.title,
this.note,
this.conclusion,
});
}
here is the code where I try to read my information
_body() {
return Column(
children: <Widget>[
Expanded(
child: ListView(children: [
Card(child: Text(widget.patients.listOfNotes.)) <------ Here
]),
),
],
);
}
patients comes from the parent it patients contains the list
widget.patients.listOfNotes
thank you for your help
CodePudding user response:
The ID for the Patient and ListNote shouldn't be the same.
@HiveType(typeId: 0)
class Patients {
@HiveType(typeId: 0)
class ListNote {
and here,
_body() {
return Column(
children: <Widget>[
Expanded(
child: ListView(children: [
Card(child: Text(widget.patients.listOfNotes.)) <-- // it is list
]),
),
],
);
}
You can access it like
children: [ // since this is a list.
...widget.patients.listOfNotes.map((e) -> Card(child: Text(e.title)))
]
if still have doubts and didn't work well, please paste your error message.
CodePudding user response:
You can use spread operator.
children: [
...widget.patients.listOfNotes.map((e) -> Card(child: Text(e.title)))
]