Skip to content

Instantly share code, notes, and snippets.

@topex-psy
Last active March 21, 2023 04:03
Show Gist options
  • Save topex-psy/245f9eff5f004b4cad1c52308cbfc46e to your computer and use it in GitHub Desktop.
Save topex-psy/245f9eff5f004b4cad1c52308cbfc46e to your computer and use it in GitHub Desktop.
Dart 2. Constant & Nullable

Dart 2. Constant & Nullable

Created with <3 with dartpad.dev.

void main() {
var nama = "Taufik";
const umur = 20;
final double? tinggi;
bool? isMarried;
bool isHasJob = true;
final jobs = <String>["Programmer", "Web Developer", "Software Engineer"];
// tidak bisa karena constant
// umur = 25;
// tidak bisa karena variabel string
// nama = 100;
tinggi = 170.0;
isMarried = false;
// tidak bisa karena tidak nullable
// isHasJob = null;
// merubah isi list (final)
jobs.clear();
jobs.addAll(["Arcitect", "Carpenter"]);
print("Nama\t: $nama");
print("Umur\t: $umur");
print("Tinggi\t: ${tinggi.toStringAsFixed(1)} cm");
print("Sudah menikah\t: ${isMarried ? "Sudah" : "Belum"}");
print("Sudah bekerja\t: ${isHasJob ? "Sudah" : "Belum"}");
print("Pekerjaan:\n${jobs.join(", ")}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment