9

I have an huge error when I try loading images from an url in flutter. I have uploaded it to hastebin: https://hastebin.com/iguvopihog.m

Here is my code:

import 'package:flutter/material.dart';
import 'package:test/news.dart';

void main() => runApp(new Main());

class Main extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Test',
      home: new Scaffold(
        body: new Image.network('www.google.de/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'),
        appBar: new AppBar(
          title: new Text("Test"),
          actions: <Widget>[
            new IconButton(icon: new Icon(Icons.menu), onPressed: null),
          ],
        ),
      ),
    );
  }
}
1
  • Have you considered writing "www"... instead of "www"... ? You usually never give a like without specifying the protocole, or the computer will think that you want to access the local folder "www.google.de" instead of the actual server. Commented Mar 11, 2018 at 17:42

1 Answer 1

23

For some reason Image.network seems to interpret the URL as file path.

Try instead setting the protocol explicitely:

body: new Image.network('http://www.google.de/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'),
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you. Sorry, I am new to flutter that is why I do not know how to do that. I did not find any suitable parameters in #network.
No worries. SO is here to get questions answered. Your question did provide the necessary information for others to answer it, that is IMHO the most important part.
for more information please refer url docs.flutter.io/flutter/widgets/Image/Image.network.html
@AarifAli thanks for your attempt to improve my answer! The changes were substantial and I'd suggest to post it as your own answer instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.