Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Display Array Object in Flutter

New member
Joined
Feb 3, 2023
Messages
3
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:

Code:
// 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:

Code:
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)

Code:
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 :(
 
New member
Joined
Feb 3, 2023
Messages
8
Your code should be as following

Code:
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

Code:
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
],```
 
Top