Hello I explain my problem I have a list of patients with their coordinates all that is registered in a class by clicking on one of the patient a life opens with the information of the patient in question.
I want to add the possibility to add notes (an unlimited number of notes per patient) so I need another list but I do not know how to link the two
I would like that when I click on a patient it loads the information of this patient from the list of notes
Here is the list of my patients
class Patients {
final String name;
final String firstname;
final String dateofbirth;
final String email;
final String numero;
final String id;
final DateTime date;
Patients(
{required this.name,
required this.firstname,
required this.dateofbirth,
required this.email,
required this.numero,
required this.id,
required this.date});
}
Here is the list of patient notes
class ListNote {
final String? title;
final String? note;
final String? conclusion;
ListNote({
this.title,
this.note,
this.conclusion,
});
}
My patient screen list
In the red frame is the information of my first list of patients.
In the blue boxes you will find the notes linked to the patient
Patient page with more info
Thank you for your help
What I got from your point is you want to add List of Notes in Patient class. If that's the case you can simply add that in Patient class like this:
class Patients {
final String name;
final List<ListNote> listOfNotes;
final String firstname;
final String dateofbirth;
final String email;
final String numero;
final String id;
final DateTime date;
Patients({
required this.name,
required this.listOfNotes,
required this.firstname,
required this.dateofbirth,
required this.email,
required this.numero,
required this.id,
required this.date
});
}
class ListNote {
final String? title;
final String? note;
final String? conclusion;
ListNote({
this.title,
this.note,
this.conclusion,
});
}
Related
I want to create an empty HiveList for my Hive class to make a relation with another Hive class. But I cannot make a default value at the constructor. I think I am doing this wrong. Unfortunately the Hive docs does not cover this issue.
#HiveType(typeId: 0)
class Account extends HiveObject {
#HiveField(0)
String name;
#HiveField(1)
int amount;
#HiveField(2)
HiveList<History> history; // Want to make this list
Account({
required this.name,
required this.amount,
this.history = [] as HiveList<History>, // Error Here
});
}
You should be able to do something like this:
#HiveType(typeId: 0)
class Account extends HiveObject {
#HiveField(0)
String name;
#HiveField(1)
int amount;
#HiveField(2)
HiveList<History> history;
Account({
required this.name,
required this.amount,
this.history = const HiveList<History>.empty(),
});
}
the structure of my database looks like this:
each user has a document in the following collection, that document also contains a collection which holds the ids of the users that he is following.
the "posts" collection has the id of the user who posted it.
now i want to query it in such a way that i get all posts from the users that my user is following (ordered by timestamp)
this is what my user & post model look like:
class PostModel {
final String id;
final String creator;
final String text;
final Timestamp timestamp;
PostModel({this.id, this.creator, this.text, this.timestamp});
}
class UserModel {
final String id;
final String email;
final int following;
final int followers;
final String profileImgUrl;
final String name;
final String bio;
final bool isVerified;
final int postAmount;
UserModel(
{this.id,
this.email,
this.following,
this.followers,
this.profileImgUrl,
this.name,
this.bio,
this.isVerified,
this.postAmount});
}
can someone help me come up with an easy way to do this in flutter?
Instead of a subcollection users you could have an array field to store the users otherwise you need to fetch the users subquery everytime which is expensive
I have Expense Model,
class Expense {
String id;
String amount;
String details;
String type;
DateTime date;
ExpenseMode mode;
Expense(
{this.id, this.amount, this.details, this.type, this.date, this.mode});
}
and Hive Model as,
#HiveType(typeId: 1)
class Expense {
#HiveField(0)
String id;
#HiveField(1)
String amount;
#HiveField(2)
String details;
#HiveField(3)
String type;
#HiveField(4)
DateTime date;
#HiveField(5)
ExpenseMode mode;
Expense(
{this.id, this.amount, this.details, this.type, this.date, this.mode});
}
Can I use only Hype Model for Expense or need to keep separate Model for Hive TypeAdapter sepefic?
Hive does not require separate Hive Model specifically to create a Type Adapter, we can edit the existing model and and convert them to Hive Model and can create Type Adaptor from it.
If I have this class :
class Person {
Person(
#required this.name,
#required this.age,
#required this.job,
});
final String name;
final int age;
final String job;
);
How can I create an object that has all these properties but set by me before the use? Something like :
Person william(name : 'William', age : 25, job : 'officer');
doSomething(william);
Please see the code below :
void main() {
final Person william = Person(name:"William", age:25, job:"officer");
doSomething(william);
}
void doSomething(Person person) {
print('${person.name} ${person.age} ${person.job}');
}
class Person {
Person({
this.name,
this.age,
this.job,
});
final String name;
final int age;
final String job;
}
I am trying to pass a few basic strings to a User Model and then on set the strings are trimmed, but my issue is if I make the passed variables to User #required and using the usual way of using set and get give me the error " Named optional parameters can't start with an underscore"
class User {
String id;
String lastName;
String email;
String _firstName;
String get firstName => _firstName;
set firstName(String name) => _firstName = name.trim();
User({#required this.id,
#required this._firstName, // Error thrown here
#required this.lastName,
#required this.email});
}
If I do the following I get static analysis errors on the set and get variables saying The declaration '_firstName' isn't referenced. Try removing the declaration of '_firstName'
class User {
String id;
String lastName;
String email;
String firstName;
String get _firstName => firstName; // Static analysis error here
set _firstName(String name) => _firstName = name.trim(); // Static analysis error here
User({#required this.id,
#required this.firstName,
#required this.lastName,
#required this.email});
}
Am I using get and set wrong? Is there a better way to do this?
EDIT : In my opinion, in your case, there is no need to use getters and setters (see documentation :
class User {
String id;
String lastName;
String email;
String firstName;
User({
#required this.id,
#required this.firstName,
#required this.lastName,
#required this.email,
}) {
firstName = firstName.trim();
}
}
Usage :
final user = User(
id: '1',
firstName: 'John',
lastName: 'Doe',
email: 'john#doe.com',
);
// set firstName :
user.firstName = 'Jane';
// get firstName :
print(user.firstName);
With getters and setters you expose a way to either get/set a value to local/private object.
Something like,
String get firstname => _firstName;
set firstName => _firstName = name.trim();
From the code you've shown, if all you're trying to do, is return a trimmed value, you can do that with only getter. Your code in that case might look as follows.
class User {
String id;
String email;
final String name;
String get firstName => name.trim();
String get lastName => name.trimLeft(); //some other calculation
User({#required this.id,
#required this.name,
#required this.email});
}