Why flutter application can't connect to internet when install app-release.apk? but normal in debug mode

bimasakti picture bimasakti · Apr 10, 2019 · Viewed 28.9k times · Source

In debug mode, everything looks good, get answers and data lists from my API. But after creating app-release.apk and installing it on my phone, there is no more internet connection

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

Answer

CopsOnRoad picture CopsOnRoad · Apr 10, 2019

In debug mode, it is not needed.

In the AndroidManifest.xml file located at android/app/src/main you need to add this permission inside the manifest tag.

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