The following leaves s null after the file read exits:
String s;
new File('etc.stk').readAsString().then((String contents) {
s = contents;
});
// s is null here.
Is there a way to save (or clone) s, or am I compelled to use it only in the .then scope?
I have a few thousand lines of compiler/interpreter code that parses and runs the file contents, and would prefer not to have them all inside the new File scope.
EDIT
To provide more context, what I am trying to do is something like
new File('etc1.stk').readAsString()
.then((String script) {
syntaxTree1 = buildTree(script);
});
new File('etc2.stk').readAsString()
.then((String script) {
syntaxTree2 = buildTree(script);
});
and have access to both syntaxTree1 and syntaxTree2 in subsequent code. I will wrap my mind around the Dart Way if I can.