Closed provokateurin closed 2 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.
Yes, but we should figure out which props are always present and which are optional to mark them accordingly
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)
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
.
Fixes https://github.com/jld3103/dart-nextcloud/issues/46