135

In debug mode, everything looks good. I get answers and data lists from my API. But after creating app-release.apk and installing it on my phone, there isn't an Internet connection any more.

Here is my code:

ScopedModelDescendant<ReportPosViewModel>(
  builder: (context, child, model) {
    return FutureBuilder<List<Invoice>>(
      future: model.invoices,
      builder: (_,
        AsyncSnapshot<List<Invoice>> snapshot) {
          switch (snapshot.connectionState) {
            case ConnectionState.none:
            case ConnectionState.active:
            case ConnectionState.waiting:
              return Center(
                child:
                  const CircularProgressIndicator());
            case ConnectionState.done:
              if (snapshot.hasData) {
                // Something todo
              }
              else if (snapshot.hasError) {
                return NoInternetConnection(
                  action: () async {
                    await model.setInvoice();
                    await getData();
                  },
                );
              }
          }
      },
    );
  },
),
0

5 Answers 5

291

Open the AndroidManifest.xml file located at <your_project>/android/app/src/main and add the following line:

<manifest xmlns:android="...">
  <uses-permission android:name="android.permission.INTERNET"/> <!-- Add this -->
</manifest>

From here:

Add the android.permission.INTERNET permission if your application code needs Internet access. The standard template does not include this tag but allows Internet access during development to enable communication between Flutter tools and a running app.

Sign up to request clarification or add additional context in comments.

13 Comments

No changes necessary for iOS?
@SoonSantos yes no changes needed for iOS.
is this necessary for flutter too??it is flutter and not java project,I used this but does not work yet
@john This isn't like Flutter or Java, rather it's for Android. And for an Android project it is necessary to use it.
@RayCoder Profile won't do the work for release, you need to put it in a place mentioned in the answer.
|
29

If you had put

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

in AndroidManifest.xml

And if it's not working, try checking the connectivity of the device. Mobile data or Wi-Fi on the Android device. Try using the Google Chrome browser for Google Search.

If it's not working, allow

8.8.8.8

in the DNS setting of the computer you are using.

5 Comments

I add to manifest internet permission but network not work, I also test in google and other browser it work. just in application not work . but its work in debug and release mode when I get aab not work
Did you find a solution for it? @RahmanRezaee
<3 try checking the connectivity of the device
After adding the permission and stil doesnt work try reinstalling the app again, I did that and it worked.
Same, i had already that persmission set, but did not work. In debug mode everything working pefectly. but after downloading it from playstore, i had SocketException: failed host lookup
23

Add this to file android/app/src/main/AndroidManifest.xml after the package name:

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

Comments

8

Add these in Android Manifest file.

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

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

Then run:

flutter clean
flutter pub get
flutter run

Comments

1

For my project, which uses Firebase, downloading the updated google-services.json from firebase console solved the issue.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.