Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

The argument type 'Iterable<dynamic>' can't be assigned to the parameter type 'List<Widget>'

Ask Question

Hi guys please i'm trying to map a list of strings in my code but its is give me the error "The argument type 'Iterable' can't be assigned to the parameter type 'List'.". I'm trying to reproduce the result in the picture below. Here is the code below;

**quote.dart**
class Quote {
  String? text;
  String? author;
  @override
  List<dynamic> quotes = [
    //"Quote" is the the name of the class of the second dart file.
    Quote(
        author: "Eminem",
        text:
            "You better lose yourself in music the moment you own it never let it go"),
    Quote(
        author: "Walt Disney",
        text: "The way to get started is to quit talking and begin doing."),
    Quote(
        author: "Mother Teresa",
        text:
            "Spread love everywhere you go. Let no one ever come to you without leaving happier")
    //     "
    //     ". -"
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey[200],
      appBar: AppBar(
        title: Text("Awesome Killer Quotes",
            style: TextStyle(
              color: Colors.grey[700],
        centerTitle: true,
        backgroundColor: Colors.yellowAccent[400],
      body: Column(
     children: quotes.map(children: quotes.map((quote) => Text('${quote.text} - 
             ${quote.author}')).toList(),
         // (quote) => Text(quote.text + "-" + quote.author).toList(),
         // ((quote) => quoteTemplate(quote).toList()),
        //return Text('>>'+quote.text+', '+quote.author);

If anybody can help me I will really appreciate it🙏🙏 P.S the error is in the main.dart file

Expected result of the code

try Change List<dynamic> quotes to List<Quote> quotes you accessing the list with it's own model you've created – Arbiter Chil Mar 11, 2022 at 16:59
Column(
    children: quotes.map((quote) => Text('${quote.text} '
        '- ${quote.author}')).toList()
                I swear i have tried this before it didn't work🤦‍♂️😟but it's working now Thanks very much🙏
– damigesh
                Mar 12, 2022 at 14:38

so try this

List<Quote> quotes = [
    //"Quote" is the the name of the class of the second dart file.
    Quote(
        author: "Eminem",
        text:
            "You better lose yourself in music the moment you own it never let it go"),
    Quote(
        author: "Walt Disney",
        text: "The way to get started is to quit talking and begin doing."),
    Quote(
        author: "Mother Teresa",
        text:
            "Spread love everywhere you go. Let no one ever come to you without leaving happier")

as your list

then your widget

return Scaffold(
      backgroundColor: Colors.grey[200],
      appBar: AppBar(
        title: Text("Awesome Killer Quotes",
            style: TextStyle(
              color: Colors.grey[700],
        centerTitle: true,
        backgroundColor: Colors.yellowAccent[400],
      body: Column(
     children: quotes.map((e)
                         =>Text('${e.text}')
         ).toList(),
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.