hukusuke1007 / flamingo

[Flutter Library] Flamingo is a firebase firestore model framework library. 🐤
https://pub.dev/packages/flamingo
MIT License
118 stars 20 forks source link

Expected a value of type 'String', but got one of type 'Null' #24

Closed kyujihub closed 3 years ago

kyujihub commented 3 years ago

Nice to meet you, my name is kyuji.

We are evaluating flamingo, but if the field increases in the model, refer to the data before the increase. I get the error "Expected a value of type'String', but got one of type'Null'". It seems to occur when there is no corresponding Field in Helper.valueFromKey in _ $ fromData (this, data). Is it possible to set Null when there is no Field? Or is it used incorrectly?

-- Japanese -- flamingoの評価をしておりますが、modelにFieldが増えた場合、増える前のデータを参照すると 「Expected a value of type 'String', but got one of type 'Null'」のエラーが発生します。 _$fromData(this, data)内の、Helper.valueFromKeyで、該当Fieldがない時に発生するようです。 Fieldがない場合に、Nullを設定する事は可能でしょうか。 それとも、使用方法が間違っていますでしょうか。

以上、宜しくお願い致します。

hukusuke1007 commented 3 years ago

Thank you for report. I will check.

hukusuke1007 commented 3 years ago

@kyujihub Please tell me model class before and after.

kyujihub commented 3 years ago

I will send you the source code before and after the change. code.zip

pierophp commented 3 years ago

I'm facing the same issue.

My workaround was change manually the generated flamingo.dart, adding a "?":

FROM

void _$fromData(FileContentLine doc, Map<String, dynamic> data) {
  doc.type = Helper.valueFromKey<String>(data, 'type');

TO

void _$fromData(FileContentLine doc, Map<String, dynamic> data) {
  doc.type = Helper.valueFromKey<String?>(data, 'type');
hukusuke1007 commented 3 years ago

I modified this bug. Please update flamingo_generator in latest version And then run build_runner.

flutter pub run build_runner build --delete-conflicting-outputs