Home > Enterprise >  How to refresh Alert Dialog without closing it in Flutter
How to refresh Alert Dialog without closing it in Flutter

Time:10-09

I am having an issue while changing the value in the alert dialog box in flutter. I want to change value of it without closing alert box

CodePudding user response:

you can use like this

 dialoge(BuildContext context) {
    showDialog(
        context: context,
        builder: (context) {
          return AlertDialog(
            scrollable: true,
            contentPadding: EdgeInsets.all(5),
            title: Center(
                child: Text(
              'Product Detail',
              style: TextStyle(
                color: yellowColor,
              ),
            )),
            content: shownecklace(selectedpp: selectedpp),
          );
        });
  }

Make alert dialogue uge box within a stateful widget

class shownecklace extends StatefulWidget {
  int selectedpp;
  shownecklace({Key? key, required this.selectedpp}) : super(key: key);

  @override
  _shownecklaceState createState() => _shownecklaceState();
}

class _shownecklaceState extends State<shownecklace> {
  @override
  Widget build(BuildContext context) {
    return Container(
      width: 675,
      height: 475,
      child: Column(
        children: [
          Padding(
            padding: const EdgeInsets.only(top: 5.0),
            child: Container(
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(5),
                color: blackColor,
              ),
              height: 460,
              child: PageView.builder(
                itemCount: ProductDetailsModel.productDetailsList.length,
                controller: PageController(initialPage: widget.selectedpp, keepPage: true, viewportFraction: 1),
                itemBuilder: (BuildContext context, int index) {
                  return Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    // mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: [
                      SizedBox(height: 10),
                      Container(
                        height: 370,
                        width: double.infinity,
                        child: PinchZoom(
                            resetDuration: const Duration(milliseconds: 4000),
                            maxScale: 2.9,
                            onZoomStart: () {
                              print('Start zooming');
                            },
                            onZoomEnd: () {
                              print('Stop zooming');
                            },
                            child: Image.network(ProductDetailsModel.productDetailsList[index].itemImg.toString(),
                                fit: BoxFit.cover, height: 270, width: double.infinity)),
                      ),
                      SizedBox(
                        height: 10,
                      ),
                      Padding(
                        padding: const EdgeInsets.only(left: 10.0, right: 12),
                        child: Container(
                          width: 250,
                          child: Column(
                            children: [
                              Row(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                children: [
                                  Text(
                                    "Product Name   :",
                                    style: TextStyle(
                                      fontSize: 14,
                                      color: yellowColor,
                                    ),
                                  ),
                                  Text(
                                    ProductDetailsModel.productDetailsList[index].itemName.toString(),
                                    style: TextStyle(fontSize: 14, color: yellowColor),
                                  )
                                ],
                              ),
                              SizedBox(
                                height: 10,
                              ),
                              Row(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                children: [
                                  Text(
                                    "Tag No   :",
                                    style: TextStyle(
                                      fontSize: 14,
                                      color: yellowColor,
                                    ),
                                  ),
                                  Text(
                                    ProductDetailsModel.productDetailsList[index].tagNo.toString(),
                                    style: TextStyle(
                                      fontSize: 14,
                                      color: yellowColor,
                                    ),
                                  )
                                ],
                              ),
                              
                              SizedBox(
                                height: 10,
                              ),
                              
                            ],
                          ),
                        ),
                      ),
                     
                    ],
                  );
                 
                },
              ),
            ),
          ),
          SizedBox(
            height: 10,
          ),
          
        ],
      ),
    );
  }
}
  • Related