Skip to content

Instantly share code, notes, and snippets.

@faizan1947
Created July 22, 2022 10:42
Show Gist options
  • Save faizan1947/ac1d73d8cc58c0ebf9ebb73605845fdf to your computer and use it in GitHub Desktop.
Save faizan1947/ac1d73d8cc58c0ebf9ebb73605845fdf to your computer and use it in GitHub Desktop.
Function as first order object

Function as first order object

Created with <3 with dartpad.dev.

void main() {
//Crate Car object
Car myCar = Car(drive: slowDrive);
//myCar.drive!();
//Now lets say upgrade car
myCar.drive = fastDrive;
myCar.drive!();
}
class Car{
Car({this.drive});
Function? drive;
}
//Top level functions , not associated with class
void slowDrive(){
print("Slowly driving");
}
void fastDrive(){
print("Driving Fast");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment