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: Flutter Officially announced that Insecure HTTP connections are disabled by default on iOS and Android. 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
Flutter Officially announced that Insecure HTTP connections are disabled by default on iOS and Android
1. For Android
- Open your
- Add below line in between your <application></application>
- Also add Internet Permission.
- <uses-permission android:name=”android.permission.INTERNET” />
- flutter clean
- 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.
- Navigate to your project.
- Go to yourapp\android\app\src\debug\AndroidManifest.xml.
- 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:
<?xml version="1.0" encoding="utf-8"?>
<certificates src="system" />
- 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
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
- How to make a blur Background Image effect in Flutter using BackdropFilter.
- Create Rounded Corners Image in Flutter.
- set Background Image to Scaffold in Flutter.
- How To Select multiple images with Flutter
- How to Set Network Image In Circular Avatar In Flutter?