//Time 0
Future.delayed(Duration(seconds:10),() => _someMethod(variableX));
//...other stuff
_someMethod() is called with the value of variableX at time 0 or with the value of variableX at time 10?
CodePudding user response:
The variableX
variable reference is evaluated when the _someMethod(variableX)
code is run, which happens in ten seconds.
If you want to keep the current value of a mutable variable, you need to keep it in a separate variable: ``dart var currentX = variableX; Future.delayed(Duration(seconds: 10), () => _someMethod(currentX));