Created
April 4, 2021 02:09
-
-
Save yeoupooh/b577ed02a26f496110cfe7435393d956 to your computer and use it in GitHub Desktop.
ListView example
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
// | |
// ListView example | |
// Created by Thomas Min | |
// | |
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: MyHomePage(), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
Widget _buildItem(BuildContext context, int index) { | |
return Card( | |
child: ListTile( | |
title: Text('item$index'), | |
subtitle: Text('blah blah'), | |
leading: | |
// Icon(Icons.play_arrow), | |
CircleAvatar( | |
backgroundColor: Colors.pink, | |
child: Text('A$index'), | |
), | |
trailing: | |
// Icon(Icons.menu), | |
CircleAvatar( | |
backgroundColor: Colors.brown.shade800, | |
child: Text('AH'), | |
), | |
onTap: () { | |
print('item$index clicked'); | |
}, | |
), | |
); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('ListView example'), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Text( | |
'ListView example', | |
), | |
Expanded( | |
child: ListView.builder( | |
itemCount: 1000, | |
itemBuilder: _buildItem, | |
), | |
), | |
], | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () { | |
print('add item'); | |
}, | |
tooltip: 'Add item', | |
child: Icon(Icons.add), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment