-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disk Cache with Generics #37025
Comments
You cannot call static methods on type parameters. The solution is to pass the function to the class constructor along with the type: class DiskCache<T> extends Cache<T> {
....
final T Function(Map<String, dynamic>) _fromMap;
DiskCache(T fromMap(Map<String, dynamic>)) : _fromMap = fromMap;
...
for (var item in parsedJson) {
allRecords.add(_fromMap(item);
}
...
} If you don't know the type where the cache is created (say, if |
See also recent discussions in dart-lang/language#356, which got into the same topic area. |
Serialization is a key part in almost all applications nowadays, I find it fundamental to dart / flutter implement a native serialization, similar or that kotlin did with a serialization plugin for the compiler which avoids the overhead of reflection at runtime , more invisibly or transparently to the programmer facilitates a lot of boilerplate code
https://github.com/Kotlin/kotlinx.serialization or a light reflection focused on serializing to json |
You may also want to look at |
I am a programmer who comes from JavaScript and PHP, and am developing an App on Flutter, and am having difficulty implementing a cache on the phone's internal storage.
I would like to understand and know if it is possible to create a Generic type class with serialization for JSON so that it can be stored on file.
I've done the Cache implementation in memory and it works fine, plus the implementation of Cache on Disk I'm having difficulty.
How to call the serialization method from a Generic
The text was updated successfully, but these errors were encountered: