Flutter 当在第三个屏幕中使用Flatter中的provider包进行任何更改时,如何更改第一个屏幕中的文本?

Flutter 当在第三个屏幕中使用Flatter中的provider包进行任何更改时,如何更改第一个屏幕中的文本?,flutter,state,state-management,Flutter,State,State Management,我有一个名为Include stateful widget的第一个屏幕,PlantFeatureScreen1,其中我必须在第三个屏幕中显示更新发生时的更改,该屏幕还包括一个stateful widget,CartDetais3 当在第三个屏幕中发生更改并且将在第三个屏幕中添加addQuantity和subtractQuantity功能时,如何更新第一个屏幕?请建议使用提供商软件包 firstScreen code这里我必须显示这个小部件树的最后一个中心小部件中的更改 class PlantFe

我有一个名为Include stateful widget的第一个屏幕,
PlantFeatureScreen1
,其中我必须在第三个屏幕中显示更新发生时的更改,该屏幕还包括一个stateful widget,
CartDetais3

当在第三个屏幕中发生更改并且将在第三个屏幕中添加
addQuantity
subtractQuantity
功能时,如何更新第一个屏幕?请建议使用提供商软件包

firstScreen code这里我必须显示这个小部件树的最后一个中心小部件中的更改

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,
                    width: double.infinity,
                    decoration: BoxDecoration(color: Colors.white),
                    child: TabBarView(
                      children: ourAllLists.tabViewerMaker(context),),),
                ],
              ),
            ),
          ),
        ),
        Padding(
          padding: const EdgeInsets.fromLTRB(20, 0, 20, 20),
          child: Container(
            alignment: Alignment.bottomRight,
            height: 120,
            width: double.infinity,
            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)))),
                  ),
                )
              ],
            ),
          ),
        )
      ],
    );
  }
}
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, 20, 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,
                                      size: 20,
                                    ),
                                  ),
                                ],
                              ))
                        ],
                      ),
                    );
                  }),
            )
          ],
        ),
      ),
    )));
  }
}

class ViewTotalItemProvider extends ChangeNotifier{
  addQuantity(index){
    OurAllLists.cartPlantList3[index].qu++;
    notifyListeners();
  }

  subtrachQuantity(index){
    OurAllLists.cartPlantList3[index].qu--;

  }
}