main.dart
import 'package:flutter/material.dart';
void main() => runApp(const FlutterExample());
class FlutterExample extends StatelessWidget {
const FlutterExample({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Example',
theme: ThemeData(primarySwatch: Colors.pink),
home: const StateExample()
);
}
}
class StateExample extends StatefulWidget {
const StateExample({Key? key}) : super(key: key);
@override
_StateExampleState createState() => _StateExampleState();
}
class _StateExampleState extends State<StateExample>{
final colors = ["Red","Green","Yellow","Blue","Black","Magenta"];
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFFFEFEFA),
appBar: AppBar(
title: const Text("Flutter - ListView Example")
),
body: bodyContent(),
);
}
bodyContent() {
return ListView.builder(
itemCount: colors.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(colors[index]),
);
}
);
}
}
![](https://fluttertuts.wordpress.com/wp-content/uploads/2021/05/516d9-flutterlistviewexample.png)
More flutter tutorials
- flutter – Image network
- flutter – ListView infinite list
- flutter – ListView separator
- flutter – ListView horizontal
- flutter – ListView icon
- flutter – ListView item click listener
- flutter – ListView IconButton
- flutter – How to disable Button
- flutter – How to use ToggleButtons
- flutter – How to change ToggleButtons color
- flutter – How to show vertical ToggleButtons
- flutter – Checkbox example
- flutter – Checkbox border color
- flutter – CheckboxListTile example
- flutter – CheckboxListTile border color