abhimanyu
abhimanyu

Reputation: 197

Convert a String into Variable in Flutter - Text Widget

I want to display a text widget using dynamic values in flutter app.

Here's my code.

class _DetailsPageState extends State<DetailsPage> {
  var descVar; 
  @override
  void initState() {
    var pick = widget.classDesc;
    var picker = "ClassesInfo."+pick;
    setState(() {
      descVar = picker;
      print(descVar);
    });
  }
...

In the build:

Text('${this.descVar}')

I wish to get value from external file:

class ClassesInfo {  
  static const String desc_class1 = "Sahaja Yoga";
}

I am just getting the string output, but not the value from the variable!

Desired Output : Sahaja Yoga

Getting Now: ClassesInfo.desc_class1

Even if i print the value in class it is getting : ClassesInfo.desc_class1

Upvotes: 0

Views: 1617

Answers (1)

Autocrab
Autocrab

Reputation: 3747

as i understood you want to print in text field value of desc_class const. So you can simply write:

Text(ClassesInfo.desc_class1)

Upvotes: 1

Related Questions