17

I´m trying to create value and name array. The problem that i don´t know what is the right way for do this.

var send=[];       

    send=[
         'latitud': widget.lat;
    ];

Somebody know how can i create array with index and values?

2 Answers 2

28

Dart uses Maps for this

to declare a map and you dont know what you will your map contain you can use

Map<String, dynamic> myObject = {'latitude': widget.lat} ;

In your Case you will need a list of objects so you can do it like that :

List<Map<String, dynamic>> send=[] ;

send.add(myObject) ;

Or :

List<Map<String, dynamic>> send=[] ;

send = [{'latitude': widget.lat}]; \\ if you want to assign it directly
Sign up to request clarification or add additional context in comments.

2 Comments

Please could you show me how i could remove the item. I mean would this work send.remove('latitude');
@samezedi In above example, send is not merely a Map, but a List of Map. Your code doesn't work because you are missing an index there. send[0].remove('latitude'); works, assuming you want to modify the first Map on the List.
22

You need a Map for that

var send = {'latitude': widget.lat};

If you really need an array, you can use for example an array of maps

var send = [{'latitude': widget.lat}, {'latitude': 123.456}];

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.