0

  var statedata = {
     "name":"sajib",
     "name2":"sajib saha",
  };

i am create and object like javascript in dart file in flutter . but i can not get access of it ? how can i get call name or name2 to get the value . in javascript i can get statedata.name but its not working here please help me ?

2 Answers 2

2

The data type you're looking at is called a Map. To access a key, you specify the key name within brackets. For example:

var statedata = {
     "name":"sajib",
     "name2":"sajib saha",
  };
  print(statedata["name2"]);

Prints:

sajib saha
Sign up to request clarification or add additional context in comments.

2 Comments

Text( statedate['_counter'], style: Theme.of(context).textTheme.headline4, ),
this give an error in text field flutter how to solve this.
0

You can make abstract class. For example:

abstract class Statedata

{
 static String name = "sajib";

 static  String name2 = "sajib saha";

}

Now you can get access like in JS:

Statedata.name //"sajib"`

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.