If you're learning clean code, you'll keep running into the "SOLID" principles. The L stands for the Liskov Substitution Principle (LSP) — a scary name for a genuinely simple idea. This guide starts from zero, so no prior knowledge is needed. What it is The Liskov Substitution Principle says: If something is supposed to work like a certain type, then any "version" of that type must be able to take its place without causing problems. That's the whole thing. If you call something a Doctor , it has to actually behave like a doctor everywhere a doctor is expected. If you call something an ApiClient , it has to behave like one everywhere. Break that, and your program fails — usually later, in a confusing way. The principle is named after Barbara Liskov, a computer scientist who described it back in 1987. But you don't need the academic version to use it well. First, what does "substitute" mean? This is the word that makes the whole pr...
ListView.builder is a versatile Flutter widget that allows you to create scrollable lists efficiently, especially when dealing with large or dynamic lists. Unlike a traditional ListView, where you provide a fixed list of children, ListView.builder generates list items on-demand as the user scrolls, which can help save memory and improve performance.
When we have to to deal with large amount of dynamically changing data or we have fetch data from the database, we have to use a ListView.builder widget.
The main difference between ListView and ListView.builder is one work with fixed data and other work with generated list items on-demand as the user scrolls, which can help save memory and improve performance.
ListView.builder widget has some additional parameters, which are:
- itemCount, is set to the length of the data source (myList), indicating the total number of items to be displayed.
- itemBuilder, defines how each list item is constructed. It receives an index, which is used to access the corresponding item in the data source.
class home extends StatelessWidget {
home({super.key});
List<String> Sub = ["CSE","EEE","CIVIL"];
List<String> FullN = ["Computer Science","Electric Engineering","Civil Engineering"];
List<int> Price =[320000,350000,470000];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"Listview Builder",
style: TextStyle(fontWeight: FontWeight.bold),
),
centerTitle: true,
backgroundColor: Colors.deepOrange,
),
body: Container(
child: ListView.builder(
itemCount: Sub.length,
itemExtent: 65,
itemBuilder: (context, index) {
return ListTile(
leading: CircleAvatar(child: Text(Sub[index][0]),),
title: Text(Sub[index]),
subtitle: Text(FullN[index]),
trailing: Text(Price[index].toString() + "/-"),
);
}),
),
);
}
}

Comments
Post a Comment