How to display variable from a class to another class

How to display variable from a class to another class I want to display variable "text" from Helper class to displaydata class how to do it. and here is my code..

void main() {
  Helper.getData('Hello World!');
} 

class Helper {
  static getData(String someText){
    var text = someText
  }
}

class displaydata{

}   

1 answer

  • answered 2019-04-15 06:23 Sami Kanafani

    I don't know if i got you correctly, you can pass the text to the constructor of the class you want to display the text in it. Hope it helps!

    void main() {
      String s = Helper.getData('Hello World!');
      DisplayData data = DisplayData(s);
      data.displayText();
    } 
    
    class Helper {
      static getData(String someText){
        var text = someText;
        return text;
      }
    }
    
    class DisplayData{
        String text;
        DisplayData(this.text);
        void displayText(){
           print(text);
        }
    
    
    }