问题描述
我有一个名为有状态窗口小部件PlantFeatureScreen1
的第一个屏幕,在其中发生更新时,我必须在第三个屏幕中显示更改,该屏幕也有一个有状态窗口小部件CartDetais3
。
当在第三屏幕中发生更改并且在第三屏幕中添加了addQuantity
和subtractQuantity
功能时,如何更新第一屏幕?请建议使用提供程序包。
firstScreen代码在这里,我必须显示此小部件树的最后一个中心小部件中的更改。
class PlantFeatureScreen1 extends StatefulWidget {
@override
_PlantFeatureScreen1State createState() => _PlantFeatureScreen1State();
}
class _PlantFeatureScreen1State extends State<PlantFeatureScreen1> {
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
TopAppBar(),Expanded(
flex: 1,child: Align(
alignment: Alignment(-1,0),child: Container(
decoration: BoxDecoration(
color: Colors.white,),child: Text(
"Plants",style: TextStyle(fontSize: 30,fontWeight: FontWeight.w700),Expanded(
flex: 5,child: Container(
width: double.infinity,decoration: BoxDecoration(
color: Colors.blue,child: DefaultTabController(
length: 5,child: Column(
children: [
Container(
height: 50,width: double.infinity,child: TabBar(
isScrollable: true,tabs: ourAllLists.tabMaker(),Container(
height: 317,decoration: BoxDecoration(color: Colors.white),child: TabBarView(
children: ourAllLists.tabViewerMaker(context),],Padding(
padding: const EdgeInsets.fromLTRB(20,20,20),child: Container(
alignment: Alignment.bottomRight,height: 120,child: Stack(
overflow: Overflow.visible,children: [
Container(
height: 70,width: 105,decoration: BoxDecoration(
color: Color(0xFF96CA2D),borderRadius: BorderRadiusDirectional.horizontal(
end: Radius.circular(32),start: Radius.circular(32))),child: Icon(FontAwesomeIcons.shoppingBag,color:Colors.white,size:30),Positioned(
// top: 0,bottom: 50,right: 0,child: Container(
height: 35,width: 35,decoration: BoxDecoration(
color: Colors.white,borderRadius: BorderRadius.circular(50),border: Border.all(color: Color(0xFF96CA2D),width: 4)
),child: Center(child: Text(ourAllLists.totalquantity().toString(),style:TextStyle(fontSize: 20,color: Color(0xFF96CA2D)))),)
],)
],);
}
}
thirdScreen代码在此处,更新是在单击+或-图标时发生的。
class CartDetais3 extends StatefulWidget {
@override
_CartDetais3State createState() => _CartDetais3State();
}
class _CartDetais3State extends State<CartDetais3> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: SafeArea(
child: Scaffold(
body: Padding(
padding: const EdgeInsets.fromLTRB(8,8,15),child: Column(
children: [
TopAppBar(),Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,children: [
Text(
"Cart",style: kPlantNameStyle,Text(
"\$" + "284",style: kItemPrice,Expanded(
child: ListView.builder(
itemCount: OurAllLists.cartPlantList3.length,itemBuilder: (context,index) {
return Card(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,children: [
Container(
height: 110,width: 100,child: Image(image: AssetImage("assets/tulip.png")),Container(
height: 80,width: 120,child: Column(
children: [
Text(OurAllLists.cartPlantList3[index].pN),Text(OurAllLists.cartPlantList3[index].ca
.toUpperCase()),Text("\$ " +
OurAllLists.cartPlantList3[index].pr
.toString()),Container(
height: 120,child: Column(
children: [
FlatButton(
onPressed: () {
setState(() {
*here addQuantity function must go*
});
},child: Icon(
FontAwesomeIcons.plus,size: 20,Text(OurAllLists.cartPlantList3[index].qu
.toString()),FlatButton(
onPressed: () {
*here subtractQuantity function must go*
},child: Icon(
FontAwesomeIcons.minus,))
],);
}),)
],)));
}
}
我还有一个名为ViewTotallItemProvider
class ViewTotalItemProvider extends ChangeNotifier{
addQuantity(index){
OurAllLists.cartPlantList3[index].qu++;
notifyListeners();
}
subtrachQuantity(index){
OurAllLists.cartPlantList3[index].qu--;
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)