ListView practice

 import "package:flutter/material.dart";


void main() {
runApp(const MyFlutter(),);
}
class MyFlutter extends StatelessWidget {
const MyFlutter({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: "Flutter ListView",
theme: ThemeData(
primarySwatch: Colors.blueGrey,
),
home: ListViewDemo(),
);
}
}
class ListViewDemo extends StatelessWidget {
ListViewDemo({super.key});

///ListView is the combination of Rows and Columns and by default the scrolldirection of ListView is "Vertical"(Column)
var arrName = ["ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN"];

/// ListView.builder
// @override
// Widget build(BuildContext context) {
// return ListView.builder(
// itemBuilder: (context, index) {
// return Text(arrName[index], style: TextStyle(fontSize: 30, fontWeight: FontWeight.w500,),);
// },
// itemCount: arrName.length,
// itemExtent: 100,
// );
// }
// }

/// ListView.separated
// @override
// Widget build(BuildContext context) {
// return ListView.separated(
// itemBuilder: (context, index) {
// return Text(arrName[index], style: TextStyle(fontSize: 30, fontWeight: FontWeight.w500,),);
// },
// itemCount: arrName.length,
// separatorBuilder: (context, index) {
// return Divider(height: 100, thickness: 7,);
// },
// );
// }

/// ListView
// @override
// Widget build(BuildContext context) {
// return ListView(
// scrollDirection: Axis.horizontal,
// //reverse: true,
// children: const [
// Padding(
// padding: EdgeInsets.all(8.0),
// child: Text("One", style: TextStyle(fontSize: 21, fontWeight: FontWeight.w500,),),
// ),
// Padding(
// padding: EdgeInsets.all(8.0),
// child: Text("Two", style: TextStyle(fontSize: 21, fontWeight: FontWeight.w500,),),
// ),
// Padding(
// padding: EdgeInsets.all(8.0),
// child: Text("Three", style: TextStyle(fontSize: 21, fontWeight: FontWeight.w500,),),
// ),
// Padding(
// padding: EdgeInsets.all(8.0),
// child: Text("Four", style: TextStyle(fontSize: 21, fontWeight: FontWeight.w500,),),
// ),
// Padding(
// padding: EdgeInsets.all(8.0),
// child: Text("Five", style: TextStyle(fontSize: 21, fontWeight: FontWeight.w500,),),
// ),
// ],
// );

/// Another practice of ListView
/// Scroll is predefined in ListView
List listNames = ["Arjun", "Ram", "Ramanujan", "Ramaswamy", "Ajay", "Karan", "Akash", "smith", "farhan"];
// @override
// Widget build(BuildContext context) {
// return ListView.builder(itemBuilder: (context, index) {
// return Center(child: Text(listNames[index], style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold,),));
// },
// itemCount: listNames.length,
// itemExtent: 200.0,
// //reverse: true,
// // scrollDirection: Axis.horizontal,
// );
// }

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("ListView"),),
body: ListView.separated(itemBuilder: (context, index) {
return Row(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
Text(listNames[index], style: const TextStyle(fontSize: 21, fontWeight: FontWeight.bold,),),
const Text("&", style: TextStyle(fontSize: 21, fontWeight: FontWeight.bold,),),
Text(listNames[index], style: const TextStyle(fontSize: 21, fontWeight: FontWeight.bold, color: Colors.purple,),),
],
),
),
const Padding(
padding: EdgeInsets.all(8.0),
child: Text("AND", style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold,),),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(listNames[index], style: const TextStyle(fontSize: 21, fontWeight: FontWeight.bold, color: Colors.red,),),
),
],
);
},
itemCount: listNames.length,
// scrollDirection: Axis.horizontal,
separatorBuilder: (context, index) {
return const Divider(height: 130, thickness: 2,);
},
),
);
}
}

Comments

Popular posts from this blog

Pagination with Bloc Pattern in Flutter

Pagination First Practical in Flutter

ExpansionPanel with ExpansionPanelList with Complete Collapse Operation in Flutter