Lear
Lear

Reputation: 29

How to override a method and keep its original code in Dart / Flutter?

i'd like to override the method "dispose" by adding a function in it (let's imagine print()), but i'd like to keep its original purpose because otherwise it sometimes throws parent stability errors. How can I do it ?

Upvotes: 0

Views: 1138

Answers (1)

Gwhyyy
Gwhyyy

Reputation: 9166

You can use the super to run inherited parent class method:

class A {
  a() {
    print("a");
   }
 }

class B extends A {
  @override
  a() {
    super.a();
    print("b");
   }
 }

now running B().a():

 B().a();

 // output:
 a
 b

Upvotes: 3

Related Questions