Reputation: 11
I tried to pass data by using provider between different widget but I got error stack over flow and the code seems nice?.
'''
Expanded(
child: ListView.builder(
itemCount: items.itemsProvide.length,
itemBuilder: (ctx, i) => CartItemsDw(
items.itemsProvide.values.toList()[i].id,
items.itemsProvide.values.toList()[i].title,
items.itemsProvide.values.toList()[i].price,
items.itemsProvide.values.toList()[i].quatity),
),
)
'''
I try to pass my data to another widget which are below there and when try to access the data for this widget the error appear
'''
import 'package:flutter/material.dart';
class CartItemsDw extends StatelessWidget {
final String id;
final String title;
final double price;
final int quantity;
CartItemsDw( this.id,this.title,this.price, this.quantity);
Widget build(BuildContext context) {
return Card(
margin: EdgeInsets.symmetric(horizontal: 10,vertical: 4),
child: Padding(padding: EdgeInsets.all(8),
child: ListTile(leading: CircleAvatar(child: Text('\$$price'),),
title: Text(title),
subtitle: Text('total \$${(price*quantity)}'),
trailing: Text('\$$quantity x'),
),
),
);
}
}
'''
Upvotes: 1
Views: 4074
Reputation: 1224
Keep in mind, Listview.builder is auto expandable and scrollable. Just remove Expanded wrapping from outside the list.
ListView.builder(
itemCount: items.itemsProvide.length,
itemBuilder: (ctx, i) => CartItemsDw(
items.itemsProvide.values.toList()[i].id,
items.itemsProvide.values.toList()[i].title,
items.itemsProvide.values.toList()[i].price,
items.itemsProvide.values.toList()[i].quatity),
);
Upvotes: 1