Malta
Malta

Reputation: 147

The argument type '({growable: bool}) → List<Card>' can't be assigned to the parameter type 'List<Widget>'

I ve a List of Strings which I want to convert via map() to a List of Card Widgets and want to render this Cards List in a column widget. I get Error mentioned above error on the "column children". I did not get whats wrong. Can anyone help me?

Thats'my Code:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  final List <String> textData = ['Dase','two'];

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: Text("App Test 1.1"),
            actions: <Widget>[
              IconButton(
                icon: Icon(Icons.ac_unit),
                tooltip: 'freeze me',
                onPressed: () {},
              )
            ],
          ),
          body: Center(
              child: Column(children: <Widget>[
            Padding(
                padding: EdgeInsets.all(20.0),
                child: RaisedButton(
                  child: Text("Add Text"),
                  onPressed: () {},
                )),
            Column(
              children: textData
              .map(
                (element) => Card(
                  margin: EdgeInsets.all(50.0),
                  child: Column(
                    children: <Widget>[
                      Text(element)
                    ],
                  ),
                ),
              ).toList,
            ),
          ]))),
    );
  }
}

In my other class it works and I cant find the difference:

class Products extends StatelessWidget {
  final List<String> products;

  Products(this.products);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: products
          .map(
            (element) => Card(
                  child: Column(
                    children: <Widget>[
                      Image.asset('assets/food.jpg'),
                      Text(element)
                    ],
                  ),
                ),
          )
          .toList(),
    );
  }
}

Upvotes: 5

Views: 1451

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657741

).toList,

should be

).toList(),

Interpretation of the error message:

'({growable: bool}) → List<Card>' is a function type where a List is expected, which indicates that a function reference was passed instead of the result of the function invocation - which usually means missing ().

Upvotes: 8

Related Questions