Flutter: protocols, do they exist?

2,012

Solution 1

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

Solution 2

In 2020, you are looking for mixin here

This is almost like a protocol in Swift, it even enables you to add function implementations.

If link does not work, seems like it does work when copy-pasted, please google dart mixin.

Share:
2,012
Little Monkey
Author by

Little Monkey

I'm just a little monkey!

Updated on December 07, 2022

Comments

  • Little Monkey
    Little Monkey over 1 year

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