0
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:testapp/cart.dart';
import 'package:testapp/cart_item.dart';

class CartScreen extends StatelessWidget {
  @override
Widget build(BuildContext context) {
    final cart = Provider.of<Cart>(context);
return new Scaffold(
  appBar: new AppBar(
    title: new Text(
      'Cart Screen',
      style:
          TextStyle(fontSize: 30.0, color: Theme.of(context).accentColor),
    ),
  ),
  body: Column(
    children: <Widget>[
      ListView.builder(
          itemCount: cart.items.length,
          itemBuilder: (ctx, i) => CartPdt(
              cart.items.values.toList()[i].id,
              cart.items.keys.toList()[i],
              cart.items.values.toList()[i].price,
              cart.items.values.toList()[i].quantity,
              cart.items.values.toList()[i].name)),
      FlatButton(
          onPressed: () {},
          child: Text(
            'CHECKOUT',
            style: TextStyle(color: Color(0xFFD1845A), fontSize: 18.0),
          ))
    ],
  ),
);

} }

why do i get an error "Too many positional arguments: 0 expected, but 5 found. Try removing the extra positional arguments, or specifying the name for named arguments" . Anyone can help me about this stuff?

2 Answers2

0

CartPdt is expecting named arguments (as defined in the CartPdt class with your parameters surrounded by curly braces {}). I'm assuming the names will be something like id, key, price, quantity, name.

Update your instantiation of the CartPdt class to this

CartPdt(
    id: cart.items.values.toList()[i].id,
    key: cart.items.keys.toList()[i],
    price: cart.items.values.toList()[i].price,
    quantity: cart.items.values.toList()[i].quantity,
    name: cart.items.values.toList()[i].name))
SupposedlySam
  • 675
  • 5
  • 14
0

here is my CartPdt code...

''' import 'package:flutter/material.dart';

class CartPdt extends StatelessWidget {
 final String id;
 final String productId;
 final double price;
 final int quantity;
 final String name;

 CartPdt ({this.id, this.productId, this.price, this.quantity, this.name});

 @override
 Widget build(BuildContext context) {
  return Card(
   child: ListTile(
    leading: CircleAvatar(
      child: FittedBox(
        child: Text('Php$price'),
      ),
    ),
    title: Text(name),
    subtitle: Text('Total: Php${(price * quantity)}'),
    trailing: Text('$quantity x'),
  ),
);

} } '''