Image in flutter’s Image.network URL does not work on physical device

Asked

Viewed 913 times

0

I made a basic app, because until then, I only used Image.asset() to put picture, now I went to put Image.network() and the URL and it worked on the AVD I created, but when I do the APK and install it on my phone, the images of Image.network(). Just now I put to run my app on my physical phone by wire and the images loads, but when I actually install (APK) does not work. Could this be a cell phone error? And also, when I made an app with an API, it only worked on AVD, when I installed it on my mobile didn’t run either.

import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(
    title: "asdas",
    home: Home(),
  ));
}

class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 2,
      child: Scaffold(
        appBar: AppBar(
          bottom: TabBar(tabs: <Widget>[
            Tab(
              icon: Icon(Icons.home),
              text: "Home",
            ),
            Tab(
              icon: Icon(Icons.file_download),
              text: "Download",
            ),
          ]),
        ),
        body: SingleChildScrollView(
          child: Container(
            child: Column(
              children: <Widget>[
                Text("lorem ipsum dolor"),
                Image.asset(
                  "images/judeu.jpg",
                  fit: BoxFit.fill,
                ),
                Image.network(
                  'https://picsum.photos/250?image=9',
                  fit: BoxFit.fill,
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
  • 2

    Added internet access permissions on Android Manifest?

  • Hello, no, I didn’t.

  • Where do I put this?

  • In the archive AndroidManifest.xml located in android/app/src/main add this line inside the tag <manifest: <uses-permission android:name="android.permission.INTERNET"/>

  • It worked, I didn’t know it.

  • Thank you very much.

  • No problem. To help other people I will post as a response and you can signal as a valid solution helping other members of the community if they have the same question as you.

Show 2 more comments

1 answer

2


Problem occurs because you do not have internet access permission set up. In mode Debug the framework already has treatments to block this access. Already in the mode release it is necessary to inform. To do this add the line below within the tag <manifest of the archive AndroidManifest.xml which is located in android/app/src/main.

<uses-permission android:name="android.permission.INTERNET"/>

Example

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.exemplo.flutter">

    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->

    <!-- Adicionar esta permissão -->
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:name="io.flutter.app.FlutterApplication"
        android:label="Exemplo"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- This keeps the window background of the activity showing
                 until Flutter renders its first frame. It can be removed if
                 there is no splash screen (such as the default splash screen
                 defined in @style/LaunchTheme). -->
            <meta-data
                android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
                android:value="true" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.