Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter cannot load image from url

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),
          ],
        ),
      ),
    );
  }
}
like image 446
Korex Avatar asked Mar 11 '18 17:03

Korex


People also ask

How do I load an image from URL in Flutter?

Displaying images is fundamental for most mobile apps. Flutter provides the Image widget to display different types of images. To work with images from a URL, use the Image.network() constructor.


1 Answers

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'),
like image 153
Günter Zöchbauer Avatar answered Oct 24 '22 18:10

Günter Zöchbauer