List - ListView
ListView
Source Code
import 'package:flutter/material.dart';
void main() {
runApp( MaterialApp(
title:"ListView ",
home:Scaffold(appBar: AppBar(title: Text(' ListView ',),),
body: Material(
child: Center(
child:
ListViewBuilderExample()
,
),
) ,
),
));
}
class ListViewBuilderExample extends StatelessWidget {
const ListViewBuilderExample({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
const numItems = 20;
const _biggerFont = TextStyle(fontSize: 18.0);
Widget _buildRow(int idx) {
return ListTile(
leading: CircleAvatar(
child: Text('$idx'),
),
title: Text(
'Item $idx',
style: _biggerFont,
),
trailing: const Icon(Icons.dashboard),
);
}
return ListView.builder(
itemCount: numItems * 2,
padding: const EdgeInsets.all(16.0),
itemBuilder: (BuildContext context, int i) {
if (i.isOdd) return const Divider();
final index = i ~/ 2 + 1;
return _buildRow(index);
},
);
}
}
Comments
Post a Comment