flutterdartabstract

Flutter Abstract class provide defaults for getter


I have an abstract class where I want two fields two have a default-value. But you should also be able to override them. Currently I have this:

abstract class Dummy {
  // ...
  Duration get progressBarAnimationDuration;
  Curve get progressBarAnimationCurve;
}

How can I give a default to these fields and also have the option to override them if needed?


Solution

  • nothing special about it being an abstract class -

    abstract class SuperClass {
      Duration get progressBarAnimationDuration => const Duration(seconds: 1);
      Curve get progressBarAnimationCurve => Curves.easeInOut;
    }
    
    class SubClass implements SuperClass {
      @override
      Duration get progressBarAnimationDuration => const Duration(seconds: 2);
      
      @override
      Curve get progressBarAnimationCurve => Curves.easeIn;
    }