Home > Blockchain >  native "AssertionError_throwNew" using cached network image in Flutter
native "AssertionError_throwNew" using cached network image in Flutter

Time:09-22

I was developing my app when I decided to put cached images on place of network images, because works much better. I made it. But my images isn't tappable anymore. When I tap to the full screen image is only white and show the error that you guys saw on the title (native "AssertionError_throwNew";) in "errors_patch.dart". I bet is because of the cached network image mixed with only network image at imageProvider inside of the PhotoView, idk. Thanks in advance and here is my code(to help more you I put the container too where are the images):

    final urlImages1 = [
     'https://i.imgur.com/Y3UejT0.jpg',
     'https://i.imgur.com/KNFL3qd.jpg',
     'https://i.imgur.com/fxAH9HY.jpg',
     'https://i.imgur.com/9GkgdKx.jpg',
    ]; 

    Widget buildImage(String urlImage01, int index) => Container(
    margin: EdgeInsets.symmetric(horizontal: 5),
    child: ClipRRect(
      borderRadius: BorderRadius.circular(20),
      child: GestureDetector(
        child: Hero(
          tag: 'imageHero',
          child: CachedNetworkImage(
            imageUrl: urlImage01,
            imageBuilder: (context, imageProvider) => Container(
              width: 350,
              height: 405,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(20),
                image: DecorationImage(
                    image: imageProvider, fit: BoxFit.cover),
              ),
            ),
            placeholder: (context, url) => SizedBox(
              width: 100,
              height: 100,
              child: Center(
                  child: CircularProgressIndicator(
                valueColor:
                    AlwaysStoppedAnimation<Color>(Colors.pink.shade700),
              )),
            ),
            errorWidget: (context, url, error) => Icon(Icons.error),
          ),
        ),
        onTap: () {
          Navigator.push(
            context,
            MaterialPageRoute(
              builder: (_) {
                return Scaffold(
                  extendBodyBehindAppBar: true,
                  appBar: AppBar(
                    elevation: 0,
                    backgroundColor: Colors.transparent,
                    leading: backIcon(),
                  ),
                  body: GestureDetector(
                    child: Center(
                      child: Hero(
                        tag: 'imageHero',
                        child: PhotoView(
                          backgroundDecoration:
                              BoxDecoration(color: Colors.black87),
                          minScale: PhotoViewComputedScale.contained * 0.9,
                          maxScale: PhotoViewComputedScale.covered * 2,
                          imageProvider: NetworkImage(
                            urlImage01,
                          ),
                        ),
                      ),
                    ),
                  ),
                );
              },
            ),
          );
        },
      ),
    ),
  );

                                          Container(
                                            width: 405,
                                            child: ClipRRect(
                                              borderRadius:
                                                  BorderRadius.only(
                                                topLeft:
                                                    Radius.circular(20),
                                                topRight:
                                                    Radius.circular(20),
                                              ),
                                              child: Column(
                                                mainAxisAlignment:
                                                    MainAxisAlignment
                                                        .center,
                                                children: [
                                                  CarouselSlider.builder(
                                                    itemCount:
                                                        urlImages1.length,
                                                    itemBuilder: (context,
                                                        index, realIndex) {
                                                      final urlImage01 =
                                                          urlImages1[index];
                                                      return buildImage(
                                                          urlImage01,
                                                          index);
                                                    },
                                                    options:
                                                        CarouselOptions(
                                                      height: 300,
                                                      enlargeStrategy:
                                                          CenterPageEnlargeStrategy
                                                              .height,
                                                      enlargeCenterPage:
                                                          true,
                                                      onPageChanged: (index,
                                                              reason) =>
                                                          setState(() =>
                                                              currentIndex =
                                                                  index),
                                                    ),
                                                  ),
                                                  SizedBox(
                                                    height: 10,
                                                  ),
                                                ],
                                              ),
                                            ),
                                          ),

CodePudding user response:

Update, guys, I was right. It was really the place I thought that was wrong. So just change this particle:

                    child: PhotoView(
                      backgroundDecoration:
                          BoxDecoration(color: Colors.black87),
                      minScale: PhotoViewComputedScale.contained * 0.9,
                      maxScale: PhotoViewComputedScale.covered * 2,
                      imageProvider: NetworkImage(
                        urlImage01,
                      ),
                    ),

to this one:

                      child: PhotoView(
                          backgroundDecoration:
                              BoxDecoration(color: Colors.black87),
                          minScale: PhotoViewComputedScale.contained * 0.9,
                          maxScale: PhotoViewComputedScale.covered * 2,
                          imageProvider: CachedNetworkImageProvider(
                            urlImage01,
                          ),
                        ),

I made it. So no worries. The problem is that I can't mark this answer as solved. Only in 2 days

  • Related