The final variable of TableData, how to use the portable setter #1897
Replies: 3 comments 3 replies
-
🤯 Damn, I forgot to have TableCompanion. Currently I only have this problem with getSingle. |
Beta Was this translation helpful? Give feedback.
-
You could instruct drift to generate mutable data classes with the I'd just use
Just use |
Beta Was this translation helpful? Give feedback.
-
I want to use TableData in the modified form. It needs to be populated during initialization. class TestTable extends Table{
TextColumn get id => text().named('ID')();
TextColumn get message text().named('Message')();
@override
Set<Column> get primaryKey => {id};
} this my conversion class class TestConvert {
String? iD;
String? message;
TestConvert({this.iD, this.message});
TestConvert.fromJson(Map<String, dynamic> json) {
iD = json['ID'];
message = json['Message'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['ID'] = this.iD;
data['Message'] = this.message;
return data;
}
} my expectations. // A testTableData that was queried
TestTableData testTable = xxx.get();
TestConvert formData = TestConvert.formJson(testTable.toJson()); But I found that the generated TableData.toJson is like this. Map<String, dynamic> toJson({ValueSerializer? serializer}) {
serializer ??= driftRuntimeOptions.defaultSerializer;
return <String, dynamic>{
'id': serializer.toJson<String>(id),
'message': serializer.toJson<String>(message),
);
} |
Beta Was this translation helpful? Give feedback.
-
👇 Example
This is wrong, are there other alternatives?
Now I use TableData.toJson and TableData.formJson, then insertOnConflictUpdate
I also encountered a small problem when developing
If there is no such data in the table, it will prompt a null error
But if I write, editor prompt always true
![image](https://user-images.githubusercontent.com/43332372/174662547-c4203727-c71b-4e0e-8ba8-dd8325f02d21.png)
In the end, I wrote it like this.
![image](https://user-images.githubusercontent.com/43332372/174663071-90e0c79c-dab1-4545-aa73-8286c8a7ae55.png)
Beta Was this translation helpful? Give feedback.
All reactions