provokateurin / dart-nextcloud

A Nextcloud client for dart
Other
20 stars 15 forks source link

Fix webdav fileid #47

Closed provokateurin closed 2 years ago

provokateurin commented 3 years ago

Fixes https://github.com/jld3103/dart-nextcloud/issues/46

ElectrifyPowr commented 3 years ago

I saw that you changed fileId to an optional variable to prevent the Null-Safety LateInit error. Wouldn't it make sense to do that for the other late variables too, so that you can check on the client side if a value even exists? Otherwise it is not easy to catch a LateInit error, whereas checking if a variable is null is easier.

provokateurin commented 3 years ago

Yes, but we should figure out which props are always present and which are optional to mark them accordingly

ElectrifyPowr commented 3 years ago

As I mentioned at the end of my issue description, I found the following variables to cause the LateInit error: note, createdDate, uploadedDate (in addition to the fileId of course)

timosturm commented 2 years ago

Yes, but we should figure out which props are always present and which are optional to mark them accordingly

The late keyword should not be used like this anyway. See effective dart. The reason here is, that we can never be sure if any of the fields are initialized or not (the only exception seems to be path as it is part of the constructor). The late keyword is appropriate for, e.g., lazy initialization but in the code we have to make sure they are initialized before being used. Here, this is not the case, for example when using the constructor: WebDavFile('/myPath/') non of the late fields are initialized.

Instead, all late fields should be converted to the respective nullable type. This allows the user to check if they are initialized: webDavFile.fileId == null or to specify a default value: webDavFile.fileId ?? 42.

provokateurin commented 2 years ago

Fixed in https://github.com/jld3103/nextcloud-harbour/blob/main/packages/nextcloud/lib/src/clients/custom/webdav/file.dart