Created
October 6, 2021 15:28
-
-
Save diegoveloper/f863bf15ac49247a859f3da908045b15 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ListViewComparison extends StatelessWidget { | |
const ListViewComparison({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
final items = List.generate(10000, (index) => _MyItem(index: index)); | |
return true | |
? ListView( | |
children: items, | |
) | |
: ListView.builder( | |
itemCount: 10000, | |
itemBuilder: (context, index) { | |
return _MyItem(index: index); | |
}); | |
} | |
} | |
class _MyItem extends StatelessWidget { | |
const _MyItem({Key? key, required this.index}) : super(key: key); | |
final int index; | |
@override | |
Widget build(BuildContext context) { | |
print('Building ... $index'); | |
return Container( | |
height: 100, | |
child: FittedBox( | |
child: Text(index.toString()), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment