Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import "package:flutter/material.dart";
- final list = <int>[];
- // Doesn't work.
- //final test = () {
- // list.add(1);
- // print("[test] list: $list"); // does nothing, no output
- // print("[test] list: " + list.elementAt(0).toString()); // does nothing, no output
- //}();
- // Doesn't work.
- //class Test {
- // Test() {
- // list.add(1);
- // print("[test] list: $list"); // does nothing, no output
- // print("[test] list: " + list.elementAt(0).toString()); // does nothing, no output
- // }
- //}
- //final test = Test();
- class App extends StatefulWidget {
- @override
- _AppState createState() => _AppState();
- }
- class _AppState extends State<App> {
- @override
- void initState() {
- super.initState();
- print("[initState] list: $list"); // empty list (any test implementation)
- //print("[initState] list: " + list.elementAt(0).toString()); // throws (any test implementation)
- list.add(1);
- print("[initState][+] list: $list"); // ok
- print("[initState][+] list: " + list.elementAt(0).toString()); // ok
- }
- @override
- Widget build(BuildContext context) {
- return MaterialApp(title: "Test", home: const Scaffold(body: Center(child: CircularProgressIndicator())));
- }
- }
- void main() {
- runApp(App());
- }
Add Comment
Please, Sign In to add comment