Skip to content

Instantly share code, notes, and snippets.

@amrahsali
Created May 29, 2025 15:10
Show Gist options
  • Save amrahsali/5ce2eb829965d5d0fddc0e5406d1c194 to your computer and use it in GitHub Desktop.
Save amrahsali/5ce2eb829965d5d0fddc0e5406d1c194 to your computer and use it in GitHub Desktop.
class BankAccount {
int _balance = 1000;
int get amount => _balance;
set amount(int value) {
if (value < 0) {
print('error message');
} else {
_balance = value;
}
}
}
void main() {
BankAccount account = BankAccount();
print(account.amount);
account.amount = -100;
print('new balace: ${account.amount}');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment