2021年5月5日星期三

lost connection of device in flutter when showing images

I have a column of widgets that show the top products in the application that show all the details of the product with an image it when it shows images of the products it lost connection of the device after 2 seconds this is the widget :

class Topproducts extends StatefulWidget {    final Size size;    final List<Products> productlist;    final Users userdata;    Topproducts(        {@required this.size, @required this.productlist, @required this.userdata});      @override    _TopproductsState createState() => _TopproductsState();  }    class _TopproductsState extends State<Topproducts> {        List toplist;    List<Products> gettoplist(List productlist) {      List<Products> toplist = [];      for (var i = 0; i < productlist.length; i++) {        if (productlist[i].getrating() >= 4.9) {          toplist.add(productlist[i]);        }      }      return toplist;    }      @override    void initState() {      super.initState();      toplist = gettoplist(widget.productlist);      toplist.removeRange(9, toplist.length - 1);    }      @override    Widget build(BuildContext context) {      return Container(        width: widget.size.width,        child: Column(          children: toplist.map((product) {            return Productbox(              product: product,              size: widget.size,              productlist: widget.productlist,              userdata:widget.userdata,            );          }).toList(),        ),      );    }  }  

this is the code of the productbox that get the image from the firebase storage :

class Productbox extends StatefulWidget {    final Size size;    final Users userdata;    final Products product;    final List productlist;    final bool isvertical;    Productbox({      @required this.size,      this.userdata,      this.productlist,      @required this.product,      this.isvertical = false,    });      Productbox.vertical({      @required this.size,      this.userdata,      this.productlist,      @required this.product,      this.isvertical = true,    });      @override    _ProductboxState createState() => _ProductboxState();  }    class _ProductboxState extends State<Productbox> {    double paddinghorizontal = 0;    double paddingvertical = 0;    dynamic imageurl;    Size size;    Products product;      @override    void initState() {      super.initState();        size = widget.size;      product = widget.product;      Storage().getproductimage(product.id).then((value) {        setState(() {          imageurl = value;        });      });    }      Widget build(BuildContext context) {      return GestureDetector(        onTap: () {          Navigator.push(            context,            MaterialPageRoute(              builder: (context) {                return Productscreen(                  product: widget.product,                  size: widget.size,                  userdata: widget.userdata,                  productslist: widget.productlist,                  imageurl: imageurl,                );              },            ),          );        },        child: Container(          padding: EdgeInsets.symmetric(            horizontal: paddinghorizontal,            vertical: paddingvertical,          ),          width: widget.isvertical              ? widget.size.width * 0.6              : widget.size.width * 0.9,          decoration: BoxDecoration(            borderRadius: BorderRadius.circular(10),            border: Border.all(              color: Colors.grey[350],              width: 1,            ),          ),          margin: EdgeInsets.only(            left: widget.size.width * 0.04,            top: widget.size.height * 0.045,            bottom: widget.size.height * 0.01,            right: widget.size.width * 0.04,          ),          child: widget.isvertical              ? Column(                  children: [                    Container(                      height: widget.size.height * 0.2,                      width: size.width * 0.45,                      decoration: BoxDecoration(                        borderRadius: BorderRadius.only(                          topLeft: Radius.circular(10),                          bottomLeft: Radius.circular(10),                        ),                      ),                      alignment: Alignment.center,                      child: imageurl.runtimeType == String                          ? Hero(                              tag: imageurl,                              child: Container(                                decoration: BoxDecoration(                                  image: DecorationImage(                                    image: NetworkImage(imageurl),                                    fit: BoxFit.fill,                                  ),                                ),                              ),                            )                          : imageurl.runtimeType == Errormodel                              ? Text(imageurl.message)                              : JumpingDotsProgressIndicator(                                  color: Theme.of(context).primaryColor,                                  dotSpacing: 3,                                  fontSize: 20,                                  numberOfDots: 3,                                  milliseconds: 400,                                ),                    ),                    Detailsbox(size: size, product: product),                  ],                )              : Row(                  children: [                    Container(                      height: size.height * 0.2,                      width: size.width * 0.45,                      decoration: BoxDecoration(                        borderRadius: BorderRadius.only(                          topLeft: Radius.circular(10),                          bottomLeft: Radius.circular(10),                        ),                      ),                      alignment: Alignment.center,                      child: imageurl.runtimeType == String                          ? Hero(                              tag: imageurl,                              child: Container(                                decoration: BoxDecoration(                                  image: DecorationImage(                                    image: NetworkImage(imageurl),                                    fit: BoxFit.fill,                                  ),                                ),                              ))                          : imageurl.runtimeType == Errormodel                              ? Text(imageurl.message)                              : JumpingDotsProgressIndicator(                                  color: Theme.of(context).primaryColor,                                  dotSpacing: 3,                                  fontSize: 20,                                  numberOfDots: 3,                                  milliseconds: 400,                                ),                    ),                    Detailsbox(                      size: size,                      product: product,                    ),                  ],                ),        ),      );    }  }  

I think that the error comes when getting the images from the storage but I don,t know the solution I am not sure

https://stackoverflow.com/questions/67410923/lost-connection-of-device-in-flutter-when-showing-images May 06, 2021 at 10:06AM

没有评论:

发表评论