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 — first linesDart
// 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

Size
639 B (639 bytes)
MIME type
text/x-dart
SHA-256
53e3bcb52aed7518a3c27362ca6dd3e6fdfd88e149407da7551002cdcfad67be
MD5
5d44ac3087e164b32ce24ff2fdf5197c

Download from the command line

curl -L -o sample.dart https://files.samplefiles.com/code/dart/sample.dart

Or check the download in your browser with the checksum calculator.