i obseved that the app is crashing after i add that listview builder if we dont add that app running smoothly
我还是一只新蜜蜂,所以我知道的不多,我刚开始学习
如果你想,你可以看到整个应用程序的代码https://github.com/Pradeep7976/E_com_app/tree/master/shop_app
这是一个垃圾,我写这个是因为堆栈溢出建议添加更多的描述它说这篇文章主要是代码添加更多的描述
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/cart.dart' show Cart;
import '../widgets/cart_item.dart';
import '../providers/orders.dart';
class CartScreen extends StatelessWidget {
static const routeName = '/cart';
@override
Widget build(BuildContext context) {
final cart = Provider.of<Cart>(context);
return Scaffold(
appBar: AppBar(
title: Text('Your Cart'),
),
body: Column(
children: <Widget>[
Card(
margin: EdgeInsets.all(5),
child: Padding(
padding: EdgeInsets.all(15),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'Total',
style: TextStyle(fontSize: 20),
),
Spacer(),
Chip(
label: Text(
'₹${cart.totalAmount.toStringAsFixed(2)}',
style: TextStyle(color: Colors.yellow),
),
backgroundColor: Theme.of(context).primaryColor,
),
FlatButton(
child: Text('ORDER NOW'),
onPressed: () {
Provider.of<Orders>(context, listen: false).addOrder(
cart.items.values.toList(),
cart.totalAmount,
);
cart.clear();
},
textColor: Theme.of(context).primaryColor,
),
],
),
),
),
SizedBox(height: 10),
Expanded(
child: ListView.builder(
itemBuilder: (ctx, i) => CartItem(
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].title,
),
itemCount: cart.items.length,
),
)
],
),
);
}
}
这种情况发生在应用程序中存在无限循环时也许你的问题是购物车项目的数量,试图建立这么多的小部件