Real apps handle many items at once: every product in a shop, every member of a WhatsApp group, every message in a chat. They also repeat the same work, such as formatting a price, in many places. Functions and collections are how programmers handle both without writing the same code again and again.
Functions
A function is a named piece of code that does one job. You give it inputs, called parameters, and it can give back a result with return.
double addTax(double amount, double rate) {
return amount + amount * rate;
}Now you can call addTax(100, 0.05) anywhere and get the answer. If the rule changes, you fix it in one place. Good functions are short, do one thing and have a clear name, such as formatCedis or isOutOfStock.
For very short functions, Dart has an arrow form:
String formatCedis(double v) => 'GHS ${v.toStringAsFixed(2)}';Dart also supports named parameters in curly braces, which make calls easier to read. You will see these everywhere in Flutter: Text('Hello', maxLines: 1).