1

I am facing a problem when working with flutter-image. I can render the image(s) from my device, but not the image(s) from the Internet!

I have to mention that I put the code in the androidManifest file to get permission for the internet as well.

But it does not work. Here is my code from the flutter documentation:

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var title = 'Web Images';

    return MaterialApp(
      title: title,
      home: Scaffold(
        appBar: AppBar(
          title: Text(title),
        ),
        body: Image.network(
          'https://picsum.photos/250?image=9',
        ),
      ),
    );
  }
}

I can't understand what the problem is! It doesn't show any errors or throw any exceptions. The image simply does not appear on the screen.

Is there anything I need to do to get the image rendered from the Internet or using url?

4
  • Image is showing when I run your code. I don't think the problem is in your code. Can you try 'flutter clean' in terminal and try again. Commented Apr 18, 2019 at 3:51
  • @Xuzan i will, if problem solves i will definitely inform here. May anything wrong with my AVD or pc. When i run flutter app, it always go previous state of the app and i need to restart app again ! Commented Apr 18, 2019 at 5:33
  • I checked the code. Are you running the app in release mode i.e. flutter run --release so if yes then check in AndroidManifest.xml you might have misplaced internet permissions. Also, make sure that the internet is working on the device/emulator. Commented Apr 18, 2019 at 10:13
  • @AmolG, I figure out the problem. Somehow my app doesn't run on the emulator according to updated code, every time i hot restart it runs with previous state of code. So i need to restart or reload twice :( But why its happening ? I tried uninstalling the app from emulator and then run again. But not work- i need to restart or reload twice to see the updated result according to my code. Strange !!! Commented Apr 18, 2019 at 14:37

1 Answer 1

1

I've tested your code and it seems working on both android emulator and iOS simulator.

Android emulator: enter image description here

iOS simulator: enter image description here

There was a filed bug regarding this issue.

Since some of the workaround have been mentioned in the the comments like checking the INTERNET is enabled if you are running in a release mode.

The default Flutter app template enables INTERNET permission for debug/profile modes (to support the Dart observatory) but not for release mode.

You could also try the following:

  • Check the configuration of the DNS in your computer. It could be a possibility that it blocks the internet connection of your android emulator.
  • Check the app with a different device (e.g. physical android device since its working in iOS), then if its working, it is something in your computer or internet to check on.

Also, other workarounds was also mentioned in the filed bug comment:

By the way there are two folders where AndroidManifest.xml appears my machine:
android/app/src/profile android/app/src/debug

Make sure you have the permissions in both

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.flloadimage">
    <uses-permission android:name="android.permission.INTERNET"/>
</manifest>

Also Here somethings else to try see if phone has problem. Login to adb shell while device is launched (or plugged in) and ping the website.

E.g. should look something like this

~$ adb shell
generic_x86:/ $ ping picsum.photos
PING picsum.photos (104.37.178.1) 56(84) bytes of data.
64 bytes from 104.37.178.1: icmp_seq=1 ttl=254 time=17.6 ms
64 bytes from 104.37.178.1: icmp_seq=2 ttl=254 time=22.4 ms
^C
--- picsum.photos ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5012ms
rtt min/avg/max/mdev = 13.638/19.442/24.621/3.508 ms
generic_x86:/  <press ctrl-d to exit to your prompt>

Other ideas

  • Try on another wifi such as a cafe.
  • Do a flutter clean command to rebuild
  • Install on another computer
Sign up to request clarification or add additional context in comments.

Comments

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.