Skip to content

Instantly share code, notes, and snippets.

@sdkdeepa
Last active March 20, 2023 07:04
Show Gist options
  • Save sdkdeepa/86380ff3d924ca3f41fb57f8dc55183e to your computer and use it in GitHub Desktop.
Save sdkdeepa/86380ff3d924ca3f41fb57f8dc55183e to your computer and use it in GitHub Desktop.
Classes and Constructors in Dart

Classes and Constructor in Dart

// Classes are blueprint for an object
// user object describried by using properties and methods
void main() {
// instantiaing a class with the User object
print("******************************");
print("To avoid hard codes values inside the class, created a constructor class.");
print("Constructor is a spl class");
print("******************************");
print('');
User userOne = User('Andy',30);
print(userOne.username);
print(userOne.age);
userOne.login();
print('');
User userTwo = User('Deepa', 35);
print(userTwo.username);
print(userTwo.age);
userTwo.login();
}
// creating a class with User object with properties such as name and age and
// with a login()
class User{
String username ;
int age;
User(this.username,this.age);
// login function inside of the User object
void login() {
print('user is logged in');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment