Skip to content

Instantly share code, notes, and snippets.

@guidezpl
Last active May 20, 2021 11:10
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save guidezpl/e41ed2678b9b9d7347880c20ec49f3f2 to your computer and use it in GitHub Desktop.
ListView example
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() => runApp(App());
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Material(
child: PerformanceMediumDemo(),
),
);
}
}
class _ListItem extends StatefulWidget {
final int index;
_ListItem({required this.index}) {
print('creating list item $index');
}
@override
_ListItemState createState() {
// print('creating list item state $index');
return _ListItemState();
}
}
class _ListItemState extends State<_ListItem> {
@override
Widget build(BuildContext context) {
print('building list item ${widget.index}');
return Container(height: 500, child: Center(child: Text(widget.index.toString())));
}
}
class PerformanceMediumDemo extends StatefulWidget {
@override
_PerformanceMediumDemoState createState() => _PerformanceMediumDemoState();
}
class _PerformanceMediumDemoState extends State<PerformanceMediumDemo> {
@override
Widget build(BuildContext context) {
return ListView(
children: [
_ListItem(index: 0),
_ListItem(index: 1),
_ListItem(index: 2),
_ListItem(index: 3),
_ListItem(index: 4),
_ListItem(index: 5),
_ListItem(index: 6),
_ListItem(index: 7),
],
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment