G1Joshi
G1Joshi

Reputation: 83

Access Static Members of a Class from Another Class in Dart/Flutter

I have 2 classes, Class A

class A {
  static void one() {
    print('One');
  }
}

and Class B

class B {
  static void two() {
    print('Two');
  }
}

I want to access the static members of these classes from a third Class C

class C {
  // Todo
}

What operations can I do to achieve this?

void main() {
  C.one(); // 'One'
  C.two(); // 'Two'
}

I want to access the static members of classes A and B from class C without creating the object of the class.

Upvotes: 1

Views: 1134

Answers (1)

shawnjb
shawnjb

Reputation: 325

Try creating static methods to access the static members of class A and B

class C {
  static void one() {
    A.one();
  }

  static void two() {
    B.two();
  }
}

Upvotes: 1

Related Questions