Guest User

Untitled

a guest
Dec 11th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. import "package:flutter/material.dart";
  2.  
  3. final list = <int>[];
  4.  
  5. // Doesn't work.
  6. //final test = () {
  7. // list.add(1);
  8. // print("[test] list: $list"); // does nothing, no output
  9. // print("[test] list: " + list.elementAt(0).toString()); // does nothing, no output
  10. //}();
  11.  
  12. // Doesn't work.
  13. //class Test {
  14. // Test() {
  15. // list.add(1);
  16. // print("[test] list: $list"); // does nothing, no output
  17. // print("[test] list: " + list.elementAt(0).toString()); // does nothing, no output
  18. // }
  19. //}
  20. //final test = Test();
  21.  
  22. class App extends StatefulWidget {
  23. @override
  24. _AppState createState() => _AppState();
  25. }
  26.  
  27. class _AppState extends State<App> {
  28. @override
  29. void initState() {
  30. super.initState();
  31.  
  32. print("[initState] list: $list"); // empty list (any test implementation)
  33. //print("[initState] list: " + list.elementAt(0).toString()); // throws (any test implementation)
  34.  
  35. list.add(1);
  36. print("[initState][+] list: $list"); // ok
  37. print("[initState][+] list: " + list.elementAt(0).toString()); // ok
  38. }
  39.  
  40. @override
  41. Widget build(BuildContext context) {
  42. return MaterialApp(title: "Test", home: const Scaffold(body: Center(child: CircularProgressIndicator())));
  43. }
  44. }
  45.  
  46. void main() {
  47. runApp(App());
  48. }
Add Comment
Please, Sign In to add comment