How to solve the error In CachedNetworkImage?












0















I want to load an image to cache. So I used CachedNetworkImage for that. When a user logged in through gmail account I get the image url and show the image. But I need to keep it in cache.
Here is my code:



new Center(
child: new Column(
children: <Widget>[
new CircleAvatar(
new CachedNetworkImage(
placeholder: CircularProgressIndicator(),
imageUrl: widget.currentUser?.profilUrl,
),
),
],
),
)


I used CachedNetworkImageProvider also but same error is coming for both. The error is



type'CachedNetworkImage'is not  a  subtype  of  type  'ImageProvider<dynamic>'









share|improve this question



























    0















    I want to load an image to cache. So I used CachedNetworkImage for that. When a user logged in through gmail account I get the image url and show the image. But I need to keep it in cache.
    Here is my code:



    new Center(
    child: new Column(
    children: <Widget>[
    new CircleAvatar(
    new CachedNetworkImage(
    placeholder: CircularProgressIndicator(),
    imageUrl: widget.currentUser?.profilUrl,
    ),
    ),
    ],
    ),
    )


    I used CachedNetworkImageProvider also but same error is coming for both. The error is



    type'CachedNetworkImage'is not  a  subtype  of  type  'ImageProvider<dynamic>'









    share|improve this question

























      0












      0








      0








      I want to load an image to cache. So I used CachedNetworkImage for that. When a user logged in through gmail account I get the image url and show the image. But I need to keep it in cache.
      Here is my code:



      new Center(
      child: new Column(
      children: <Widget>[
      new CircleAvatar(
      new CachedNetworkImage(
      placeholder: CircularProgressIndicator(),
      imageUrl: widget.currentUser?.profilUrl,
      ),
      ),
      ],
      ),
      )


      I used CachedNetworkImageProvider also but same error is coming for both. The error is



      type'CachedNetworkImage'is not  a  subtype  of  type  'ImageProvider<dynamic>'









      share|improve this question














      I want to load an image to cache. So I used CachedNetworkImage for that. When a user logged in through gmail account I get the image url and show the image. But I need to keep it in cache.
      Here is my code:



      new Center(
      child: new Column(
      children: <Widget>[
      new CircleAvatar(
      new CachedNetworkImage(
      placeholder: CircularProgressIndicator(),
      imageUrl: widget.currentUser?.profilUrl,
      ),
      ),
      ],
      ),
      )


      I used CachedNetworkImageProvider also but same error is coming for both. The error is



      type'CachedNetworkImage'is not  a  subtype  of  type  'ImageProvider<dynamic>'






      dart flutter






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 '18 at 7:59









      Falak Falak

      224




      224
























          2 Answers
          2






          active

          oldest

          votes


















          1














          The widget CircleAvatar receives an ImageProvider.



          The cached_network_image package offers you two classes to use:





          1. CachedNetworkImage a Widget you can use to display a cached network image.


          2. CachedNetworkImageProvider an ImageProvider providing the cached image.


          Therefore you gotta use CachedNetworkImageProvider(2.), if you want to pass it to the CircleAvatar.



          Here is a complete example, that you can copy & paste for trying out:



          import 'package:flutter/material.dart';
          import 'package:cached_network_image/cached_network_image.dart';

          void main() => runApp(MyApp());

          class MyApp extends StatelessWidget {
          @override
          Widget build(BuildContext context) {
          return MaterialApp(
          theme: ThemeData(),
          home: Scaffold(
          body: Center(
          child: CircleAvatar(
          backgroundImage: CachedNetworkImageProvider(
          'https://upload.wikimedia.org/wikipedia/commons/thumb/7/71/Bill_Gates_Buys_Skype_%285707954468%29.jpg/2560px-Bill_Gates_Buys_Skype_%285707954468%29.jpg'
          ),
          ),
          ),
          )
          );
          }
          }





          share|improve this answer


























          • Yes, I used CachedNetworkImageProvider but same kind of error is showing.

            – Falak
            Nov 21 '18 at 8:18











          • @Falak I added a complete example, you can copy & paste it and try it out. Is the same kind of error still showing up?

            – Niklas
            Nov 21 '18 at 8:25











          • Thank you it's working.

            – Falak
            Nov 21 '18 at 8:50



















          0














          Just like @Niklas say.




          The widget CircleAvatar receives an ImageProvider.




          this is how to use:



           new Center(
          child: new Column(
          children: <Widget>[
          new CircleAvatar(
          backgroundImage: new CachedNetworkImageProvider(
          widget.currentUser?.profilUrl,
          )
          ),
          ],
          ),
          )





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53407527%2fhow-to-solve-the-error-in-cachednetworkimage%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            The widget CircleAvatar receives an ImageProvider.



            The cached_network_image package offers you two classes to use:





            1. CachedNetworkImage a Widget you can use to display a cached network image.


            2. CachedNetworkImageProvider an ImageProvider providing the cached image.


            Therefore you gotta use CachedNetworkImageProvider(2.), if you want to pass it to the CircleAvatar.



            Here is a complete example, that you can copy & paste for trying out:



            import 'package:flutter/material.dart';
            import 'package:cached_network_image/cached_network_image.dart';

            void main() => runApp(MyApp());

            class MyApp extends StatelessWidget {
            @override
            Widget build(BuildContext context) {
            return MaterialApp(
            theme: ThemeData(),
            home: Scaffold(
            body: Center(
            child: CircleAvatar(
            backgroundImage: CachedNetworkImageProvider(
            'https://upload.wikimedia.org/wikipedia/commons/thumb/7/71/Bill_Gates_Buys_Skype_%285707954468%29.jpg/2560px-Bill_Gates_Buys_Skype_%285707954468%29.jpg'
            ),
            ),
            ),
            )
            );
            }
            }





            share|improve this answer


























            • Yes, I used CachedNetworkImageProvider but same kind of error is showing.

              – Falak
              Nov 21 '18 at 8:18











            • @Falak I added a complete example, you can copy & paste it and try it out. Is the same kind of error still showing up?

              – Niklas
              Nov 21 '18 at 8:25











            • Thank you it's working.

              – Falak
              Nov 21 '18 at 8:50
















            1














            The widget CircleAvatar receives an ImageProvider.



            The cached_network_image package offers you two classes to use:





            1. CachedNetworkImage a Widget you can use to display a cached network image.


            2. CachedNetworkImageProvider an ImageProvider providing the cached image.


            Therefore you gotta use CachedNetworkImageProvider(2.), if you want to pass it to the CircleAvatar.



            Here is a complete example, that you can copy & paste for trying out:



            import 'package:flutter/material.dart';
            import 'package:cached_network_image/cached_network_image.dart';

            void main() => runApp(MyApp());

            class MyApp extends StatelessWidget {
            @override
            Widget build(BuildContext context) {
            return MaterialApp(
            theme: ThemeData(),
            home: Scaffold(
            body: Center(
            child: CircleAvatar(
            backgroundImage: CachedNetworkImageProvider(
            'https://upload.wikimedia.org/wikipedia/commons/thumb/7/71/Bill_Gates_Buys_Skype_%285707954468%29.jpg/2560px-Bill_Gates_Buys_Skype_%285707954468%29.jpg'
            ),
            ),
            ),
            )
            );
            }
            }





            share|improve this answer


























            • Yes, I used CachedNetworkImageProvider but same kind of error is showing.

              – Falak
              Nov 21 '18 at 8:18











            • @Falak I added a complete example, you can copy & paste it and try it out. Is the same kind of error still showing up?

              – Niklas
              Nov 21 '18 at 8:25











            • Thank you it's working.

              – Falak
              Nov 21 '18 at 8:50














            1












            1








            1







            The widget CircleAvatar receives an ImageProvider.



            The cached_network_image package offers you two classes to use:





            1. CachedNetworkImage a Widget you can use to display a cached network image.


            2. CachedNetworkImageProvider an ImageProvider providing the cached image.


            Therefore you gotta use CachedNetworkImageProvider(2.), if you want to pass it to the CircleAvatar.



            Here is a complete example, that you can copy & paste for trying out:



            import 'package:flutter/material.dart';
            import 'package:cached_network_image/cached_network_image.dart';

            void main() => runApp(MyApp());

            class MyApp extends StatelessWidget {
            @override
            Widget build(BuildContext context) {
            return MaterialApp(
            theme: ThemeData(),
            home: Scaffold(
            body: Center(
            child: CircleAvatar(
            backgroundImage: CachedNetworkImageProvider(
            'https://upload.wikimedia.org/wikipedia/commons/thumb/7/71/Bill_Gates_Buys_Skype_%285707954468%29.jpg/2560px-Bill_Gates_Buys_Skype_%285707954468%29.jpg'
            ),
            ),
            ),
            )
            );
            }
            }





            share|improve this answer















            The widget CircleAvatar receives an ImageProvider.



            The cached_network_image package offers you two classes to use:





            1. CachedNetworkImage a Widget you can use to display a cached network image.


            2. CachedNetworkImageProvider an ImageProvider providing the cached image.


            Therefore you gotta use CachedNetworkImageProvider(2.), if you want to pass it to the CircleAvatar.



            Here is a complete example, that you can copy & paste for trying out:



            import 'package:flutter/material.dart';
            import 'package:cached_network_image/cached_network_image.dart';

            void main() => runApp(MyApp());

            class MyApp extends StatelessWidget {
            @override
            Widget build(BuildContext context) {
            return MaterialApp(
            theme: ThemeData(),
            home: Scaffold(
            body: Center(
            child: CircleAvatar(
            backgroundImage: CachedNetworkImageProvider(
            'https://upload.wikimedia.org/wikipedia/commons/thumb/7/71/Bill_Gates_Buys_Skype_%285707954468%29.jpg/2560px-Bill_Gates_Buys_Skype_%285707954468%29.jpg'
            ),
            ),
            ),
            )
            );
            }
            }






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 21 '18 at 8:25

























            answered Nov 21 '18 at 8:13









            NiklasNiklas

            53428




            53428













            • Yes, I used CachedNetworkImageProvider but same kind of error is showing.

              – Falak
              Nov 21 '18 at 8:18











            • @Falak I added a complete example, you can copy & paste it and try it out. Is the same kind of error still showing up?

              – Niklas
              Nov 21 '18 at 8:25











            • Thank you it's working.

              – Falak
              Nov 21 '18 at 8:50



















            • Yes, I used CachedNetworkImageProvider but same kind of error is showing.

              – Falak
              Nov 21 '18 at 8:18











            • @Falak I added a complete example, you can copy & paste it and try it out. Is the same kind of error still showing up?

              – Niklas
              Nov 21 '18 at 8:25











            • Thank you it's working.

              – Falak
              Nov 21 '18 at 8:50

















            Yes, I used CachedNetworkImageProvider but same kind of error is showing.

            – Falak
            Nov 21 '18 at 8:18





            Yes, I used CachedNetworkImageProvider but same kind of error is showing.

            – Falak
            Nov 21 '18 at 8:18













            @Falak I added a complete example, you can copy & paste it and try it out. Is the same kind of error still showing up?

            – Niklas
            Nov 21 '18 at 8:25





            @Falak I added a complete example, you can copy & paste it and try it out. Is the same kind of error still showing up?

            – Niklas
            Nov 21 '18 at 8:25













            Thank you it's working.

            – Falak
            Nov 21 '18 at 8:50





            Thank you it's working.

            – Falak
            Nov 21 '18 at 8:50













            0














            Just like @Niklas say.




            The widget CircleAvatar receives an ImageProvider.




            this is how to use:



             new Center(
            child: new Column(
            children: <Widget>[
            new CircleAvatar(
            backgroundImage: new CachedNetworkImageProvider(
            widget.currentUser?.profilUrl,
            )
            ),
            ],
            ),
            )





            share|improve this answer




























              0














              Just like @Niklas say.




              The widget CircleAvatar receives an ImageProvider.




              this is how to use:



               new Center(
              child: new Column(
              children: <Widget>[
              new CircleAvatar(
              backgroundImage: new CachedNetworkImageProvider(
              widget.currentUser?.profilUrl,
              )
              ),
              ],
              ),
              )





              share|improve this answer


























                0












                0








                0







                Just like @Niklas say.




                The widget CircleAvatar receives an ImageProvider.




                this is how to use:



                 new Center(
                child: new Column(
                children: <Widget>[
                new CircleAvatar(
                backgroundImage: new CachedNetworkImageProvider(
                widget.currentUser?.profilUrl,
                )
                ),
                ],
                ),
                )





                share|improve this answer













                Just like @Niklas say.




                The widget CircleAvatar receives an ImageProvider.




                this is how to use:



                 new Center(
                child: new Column(
                children: <Widget>[
                new CircleAvatar(
                backgroundImage: new CachedNetworkImageProvider(
                widget.currentUser?.profilUrl,
                )
                ),
                ],
                ),
                )






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 21 '18 at 9:03









                dujianchidujianchi

                1967




                1967






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53407527%2fhow-to-solve-the-error-in-cachednetworkimage%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Tangent Lines Diagram Along Smooth Curve

                    Yusuf al-Mu'taman ibn Hud

                    Zucchini