-
Notifications
You must be signed in to change notification settings - Fork 405
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
[Feature Request] Generic Types for Box #45
Comments
What exactly do you mean? You can store any object in a box. |
Ex, if I want a box to store only |
This only works with values because the |
Maybe |
I'll implement that 👍 |
I thought about this and (afaik) it is impossible to implement this. The best example are lists: You cannot cast If you have a solution for this problem, I would happily implement this feature. |
I think it can be implemented by using this approach but that would require a little bit of boilerplate and that would be hacky, so closing this issue. Would re-open if I got any neat solution. |
Instead of that approach we can add an anonymous function to convert List and Map such as Hive.openBox<List<int>>('box', castToList: (l)=>l.cast<int>().toList()) in T Function(List<dynamic> l) castToList;
T Function(Map<dynamic, dynamic> m) castToMap;
BoxImpl(... , {this.castToList, this.castToMap} ...) //constructor
...
T get(dynamic key, {T defaultValue}){
...
if(frame.value is List)
return castToList(frame.value);
if(frame.value is Map)
return castToMap(frame.value); but still requires some boilerplate and a little bit confusing. |
Unfortunately I think this is a major flaw of the language :/ |
I mean they can provide a function to convert (list) => (l.map((l) => l.cast<int>().toList()).toList().cast<List<int>>().toList()) |
It would be great if
Box
support generic types such asBox<K, V>
.The text was updated successfully, but these errors were encountered: