Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: protocols, do they exist?

I can't find a way to create a Swift protocol in Flutter. Do they exist or are there other replacement ways?

like image 358
Little Monkey Avatar asked Jun 16 '26 06:06

Little Monkey


1 Answers

In Dart you just create an abstract class and put all the methods you want its children to override. You can also provide an implementation:

abstract class MyAbstractClass {
  
  void method1(); // children must implement this method
   
  void method2() { // this method already has an implementation
    print("Just a print");
  }
  
}
like image 100
Daniel Oliveira Avatar answered Jun 18 '26 23:06

Daniel Oliveira