这是我的BottomModalSheet代码:
onTap: () async{
await scaffoldKey.currentState
.showBottomSheet((context) =>
StatefulBuilder(
builder: (BuildContext context,StateSetter setState){
return
Container(
color: Colors.white,
height: MediaQuery.of(context).size.height,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
height: 200,
color: Colors.black,
),
Container(
height: 100,
width: MediaQuery.of(context).size.width,
color: Colors.cyan,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('DELIVERY AT',style: TextStyle(fontSize: 12),),
SizedBox(height: 5,),
Row(
children: <Widget>[
Container(
margin:EdgeInsets.only(top: 5),
child: Icon(Icons.check_circle,color: Colors.black,)),
SizedBox(width: 5,),
Text('Area Code ',style: TextStyle(fontSize: 14),),
_userPin!=null?Text(_userPin,style: TextStyle(fontSize: 16),):Container(),
],
),
Container(
margin: EdgeInsets.only(left: 30,top: 5),
child: Text('We will try to deliver in 60 minutes',style: TextStyle(fontSize: 12),))
],
),
),
),
Container(
child: Expanded(
child: ListView.builder(
shrinkWrap: true,
itemCount: cart.toSet().toList().length,
itemBuilder: (context, index){
return Padding(
padding: const EdgeInsets.all(12.0),
child: Container(
height: 65,
decoration: BoxDecoration(borderRadius: BorderRadius.circular(10),color: Colors.black),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
child: Text('${cart[index].Counter}',style: TextStyle(color: Colors.white),)),
Container(
child: Text(cart[index].OurPrice,style: TextStyle(color: Colors.white),)),
Container(
child: Text(cart[index].Name,style: TextStyle(color: Colors.white),))
],
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
InkWell(
onTap: (){
if(totalItems.length>=1){
totalPrice.remove(int.parse(cart[index].OurPrice));
cart.remove(categoryItemList[index]);
cart[index].Counter--;
totalItems.remove(1);
print(totalPrice);}
else
{
print('No item left in cart');
}
setState(() {
});
},
child: Container(
height: 60,width: 50,
decoration: BoxDecoration(color: Colors.redAccent,borderRadius: BorderRadius.only(topRight: Radius.circular(10)
,bottomRight: Radius.circular(10))),
child: Icon(Icons.delete,size: 28,),
),
)
],
),
],
)
),
);
}),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
margin: EdgeInsets.only(bottom: 10),
height: 50,width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(color: Colors.cyan,borderRadius: BorderRadius.circular(10)),
child:Center(child: Text('Proceed to Checkout',textAlign: TextAlign.center,style: TextStyle(fontSize: 16,fontWeight: FontWeight.w600),)) ,
),
)
],
),
);
}
),
);
},
我在这里附上我的屏幕截图:
ScreenShot 1:ss1
ScreenShot 2:ss2
在单击屏幕快照1中的购物车时,如图2所示,打开BottomModalSheet,然后按ss2中显示的删除按钮,则其中一项被删除,我希望在父屏幕上对其进行更新,即ss1。我尝试通过使此方法异步来完成此操作,但失败了。即使我希望我的列表项目在特定项目的项目计数变为0时也从屏幕(ss2)中消失。我能够在Ss2屏幕上更改项目计数,但是我希望项目计数为1并按Delete键时再次它将其从屏幕I ss2中删除。