简体   繁体   中英

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),
          ],
        ),
      ),
    );
  }
}

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'),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM