-
-
Notifications
You must be signed in to change notification settings - Fork 153
Not able to change values in registered singleton or user error? #116
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
Comments
That's kinda weird. you mean that if you do |
Precisely - the data isn't changed. Here you go Press the floating button multiple times once loaded. Let me know if the example is not clear. Thanks |
I was a bit perplexed too here for a moment but it behaves as it should. you can try this here: class Container{
List list = [1,2,3];
}
void main() {
final container = Container();
var cache = container.list;
cache = [5,6,7];
print(container.list);
} the surprising thing is , if you don't assign but do an addall on cache it works as you thought. |
Shouldn't be the reverse? as in
|
that would work, but you asked exactly my code rebuilds |
Sorry, I didn't understand your last comment regarding code rebuilds. Maybe I am confusing stuff, but why would: |
I am probably misunderstanding how the code is compiled and the ordering of stuff here. Do you have any suggestion how one would store a cache? Do I need to set the variable inside a Factory Singleton to always return the same variable? Thanks again |
sorry I didn't mean real rebuilds but that my example simulates what you asked. factory Commands(){
List cache = sl<MemoryDatabase>().cache;
final _doSomething = RxCommand.createSyncNoParam<List>(){
// some work is done with an output of newCache
// this does not work, but I don't get why <<<<<<--------------------------- QUESTION IS HERE
cache = newCache; // this can't work see my example
// and this works
sl<MemoryDatabase>().cache = newCache; /// this here works it's like doing `container.list=cache`
return [newCache]
}; |
Looking at it again, I actually think it is not the same as the example. It is the reverse as below. Am I getting it wrong?
|
Nope :-)
|
Ah I think I'm getting it. This is some Dart trickery! and user error :-) Make me wish for pointers. |
yep! I too think pointers would be clearer here. If you use addAll instead of the assignment it works because then |
The text was updated successfully, but these errors were encountered: