Search code examples
dartflutterprotocols

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?


Solution

  • 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");
      }
      
    }