Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Display Array Object in Flutter

hope you guys have a great day!

I’am learning Flutter, and now i got some obstacle to display data from array object, so i have the array object look like this:

// i saved this array object to listLorem var
listLorem = [
    {
        "ids": 12,
        "someText": "Lorem Ipsum #12",
    },
    {
        "ids": 11,
        "someText": "Lorem Ipsum #11",
    },
]

and then, i want to display it on my DropDownItems, somethins looks like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

items: [
 DropdownMenuItem(                                                          
  child: Text("Choose One"),
  value: "",
 ),
 listLorem.map((items) => DropdownMenuItem(
  child: Text(items.someText),
  value: items.ids,
 )),
],

====== EDIT =========

and this is my console said (with all red)

listLorem((items) => DropdownMenuItem(
                                                                                          ^
: Error: The argument type 'List<Object>' can't be assigned to the parameter type 'List<DropdownMenuItem<String>>?'.
register.dart:569
 - 'List' is from 'dart:core'.
 - 'Object' is from 'dart:core'.
- 'DropdownMenuItem' is from 'package:flutter/src/material/dropdown.dart' ('../../../../../flutter/packages/flutter/lib/src/material/dropdown.dart').

i’ve tried others method, but i still didn’t know how to do it right, i got "redline" all over the place 🙁

>Solution :

Your code should be as following

items: [
 DropdownMenuItem(                                                          
  child: Text("Choose One"),
  value: "",
 ),
 ...listLorem.map((items) => DropdownMenuItem(
  child: Text(items.someText),
  value: items.ids,
 )),//...(triple dots) is represents list is getting appended
],

Or

items: [
 DropdownMenuItem(                                                          
  child: Text("Choose One"),
  value: 0,
 ),
 ...listLorem.map((items) => DropdownMenuItem(
  child: Text(items.someText),
  value: items.ids,
 )),//...(triple dots) is represents list is getting appended
],```
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading