Code · 1 file
Sample Dart File
Dart is the language behind Flutter apps. The Dart sample is a small program — a customer record, a VIP check and a formatted total — that is the same in every language we offer, so you can compare them side by side.
Dart · 639 B
Sample Dart file
An idiomatic Dart example: a customer record type, a VIP check, a total and a formatted loop — the same program in every language we offer.
CC0 · free for any use · Verified by an independent tool · Report a problem
// Sample Dart program — samplefiles.com
class Customer {
final int id;
final String name;
final double balance;
const Customer(this.id, this.name, this.balance);
bool get isVip => balance >= 10000;
}
double totalBalance(List<Customer> customers) => customers.fold(0, (sum, c) => sum + c.balance);
void main() {
const customers = [Customer(1, 'Ada', 12500), Customer(2, 'Grace', 830.5), Customer(3, 'Linus', 10000)];
for (final c in customers) {
print('${c.name.padRight(6)} ${c.balance.toStringAsFixed(2).padLeft(10)} ${c.isVip ? 'VIP' : ''}');
}
print('Total: ${totalBalance(customers).toStringAsFixed(2)}');
}File details
Download from the command line
curl -L -o sample.dart https://files.samplefiles.com/code/dart/sample.dartwget https://files.samplefiles.com/code/dart/sample.darthttps://files.samplefiles.com/code/dart/sample.dartprintf '%s %s\n' 53e3bcb52aed7518a3c27362ca6dd3e6fdfd88e149407da7551002cdcfad67be sample.dart | shasum -a 256 -cOr check the download in your browser with the checksum calculator.