close

[Solved] Flutter insecure HTTP is not allowed by platform

Hello Guys How are you all? Hope You all are fine. When I was trying to run my flutter app and suddenly I get the following error in my stack track. Bad state: Insecure HTTP is not allowed by platform in a flutter. So today Here I come with all possible solutions for this error.

We are providing you all possible solutions to solve this error. let’s start this article without wasting your time.

How Bad state: Insecure HTTP is not allowed by platform Error Occurs ?

I am trying to get data from API. but my API url is http. So when I run my app having the following problem:

E/flutter ( 7144): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: Bad state: Insecure HTTP is not allowed by platform

How to Solve Bad state: Insecure HTTP is not allowed by platform Error?

Question: How to Solve Bad state: Insecure HTTP is not allowed by platform Error?
Answer: To solve insecure HTTP is not allowed by platform just Open your android/app/src/main/AndroidManifest.xml. Add below line in between your
android:usesCleartextTraffic=”true” Also add Internet Permission. flutter clean Flutter run

Solution 1

Flutter Officially announced that Insecure HTTP connections are disabled by default on iOS and Android

1. For Android

  1. Open your android/app/src/main/AndroidManifest.xml.
  2. Add below line in between your <application></application>
  3. android:usesCleartextTraffic=”true”
  4. Also add Internet Permission.
  5. <uses-permission android:name=”android.permission.INTERNET” />
  6. flutter clean
  7. Flutter run

2. For iOS

Allow insecure/HTTP requests globally across your application on iOS, you can add this to your ios/Runner/info.plist under the main dictionary definition:

Be warned that you will need to have an explanation for Apple’s review team when enabling this, otherwise your app will get rejected on submission.

  • Open your ios/Runner/Info.plist
  • Add below line in info.plist file.
  • Flutter clean
  • Flutter run.

Also watch My full video for batter understanding.

Solution 2

  1. Navigate to your project.
  2. Go to yourapp\android\app\src\debug\AndroidManifest.xml.
  3. Add this line.

Solution 3 : 100% Working

If Above 2 Not Worked then 100% This solution will work

  • Go to this path: yourProject\android\app\src\main\res
    and create a folder named XML
  • open this path: yourProject\android\app\src\main\res\xml and create xml file named network_security_config.xml
  • inside network_security_config.xml file write this:
  • You need to go to this path: yourProject\android\app\src\main\AndroidManifest.xml:
  • stop and restart your application and it will work with you

Summery

So, It’s All About How to use Conditional statement in widget in flutter. I hope this tutorial helps you to solve your error. Please Comment Below if You stucks anywhere with my code.

Also Check Out Below Tutorials

Leave a Comment

%d bloggers like this: