I'm using Dart in a Django application. There are configuration parameters that need to be passed to Dart. How do you pass values to main()? At this point I'm considering creating hidden elements in the web page and using query to get the values. Is there a better approach?
How to Declare Variable in Dart. We need to declare a variable before using it in a program. In Dart, The var keyword is used to declare a variable. The Dart compiler automatically knows the type of data based on the assigned to the variable because Dart is an infer type language.
Dart does not support passing by reference. Dart is only passed by value, just like Java. Java also does not support reference passing.
Sounds like you are building a browser app?
(BTW, you can use new Options().arguments
for command-line apps. Works great, but obviously there is no command line in browser apps :)
(Second, main()
doesn't take arguments, so we have to find another way.)
OK, for a browser-app, what I might try doing is embedding some JSON into the page inside a <script>
tag. Then, using query, find that element, parse the contents, and you're good to go.
In your HTML:
<script id="config">
{"environment":"test"}
</script>
And in your Dart file:
import 'dart:html';
import 'dart:json' as json;
void main() {
var config = json.parse(query("#config").innerHtml);
print(config['environment']);
}
Hope that helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With