List View Flutter Code
ListView is a method that shows several types of items and displays them up to down or reverses and left to right or reverse. In Android and Flutter, code is used as name.
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Test Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'My Flutter Testing'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
var arrnames = ['Sanjay', 'Ajay', 'John', 'Dev', 'Moon', 'Mohit', 'Abhiraj', 'Amit Kumar'];
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text('List View'),
),
body: ListView.separated(itemBuilder: (context, index){
//Call array name & index data
return Text(arrnames[index], style: TextStyle(fontSize: 25, fontWeight: FontWeight.w800),);
},
itemCount: arrnames.length, //print to all length of index data
// list view is already predefined for scroll
//Set scroll direction left to right or right to left, up to down or down to up via using scroll direction
separatorBuilder: (context, index){
return Divider(height: 5, thickness: 2, color: Colors.red,);
},
)
);
}
}
Output
