Flutter Abstract class provide defaults for getter

63 Views Asked by At

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?

1

There are 1 best solutions below

1
Hallel On BEST ANSWER

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