On the screen I expect to see an ever growing list:
- 0
- 1
- 2
- ...
but it's just black. If I hit CTRL+S in Android Studio all of a sudden the whole list is finally shown.
import 'dart:async';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
List<Widget> list = [];
@override
Widget build(BuildContext context) {
print('${list.length}');
return MaterialApp(
home: ListView(
children: list,
),
);
}
@override
void initState() {
super.initState();
new Timer.periodic(const Duration(seconds: 1), (timer) {
setState(() {
list.add(Text('${list.length}', key: Key(list.length.toString())));
});
});
}
}
At first I thought it was because I wasn't setting key property, but I added that and still nothing.
I know the build() property is being triggered every second because I see the print() statement showing the numbers in the debug Run tab output.
What am I missing here? It's got to be something simple!