Flutter local api connection wont work on Emulator/Android sid
I created an endpoint on my Django app like: /accounts/api/login/. It checks the login inputs and returns JSON. On the Visual Studio Code side, the flutter run command allows me to log in successfully. But if I try the app on the Android Studio Emulator or my Android mobile, the same log occurs:
2025-05-13 11:25:45.485 11034-11034 flutter com.example.depo_app I Login Exception: Connection failed
2025-05-13 11:25:45.485 11034-11034 flutter com.example.depo_app I #0 IOClient.send (package:http/src/io_client.dart:94)
2025-05-13 11:25:45.485 11034-11034 flutter com.example.depo_app I <asynchronous suspension>
2025-05-13 11:25:45.485 11034-11034 flutter com.example.depo_app I #1 BaseClient._sendUnstreamed (package:http/src/base_client.dart:93)
2025-05-13 11:25:45.485 11034-11034 flutter com.example.depo_app I <asynchronous suspension>
2025-05-13 11:25:45.485 11034-11034 flutter com.example.depo_app I #2 _withClient (package:http/http.dart:166)
2025-05-13 11:25:45.485 11034-11034 flutter com.example.depo_app I <asynchronous suspension>
2025-05-13 11:25:45.485 11034-11034 flutter com.example.depo_app I #3 _LoginPageState._login (package:depo_app/main.dart:76)
2025-05-13 11:25:45.485 11034-11034 flutter com.example.depo_app I <asynchronous suspension>
2025-05-13 11:25:45.485 11034-11034 flutter com.example.depo_app I
I think it's happening because the web side is not https, but my system needs to work on a local server. I tried to use the runserver_plus ... --cert-file ...
method too, but this time, pyOpenSSL library installation errors occurred, and I gave up. (After installing pyOpenSSL and all requirements.txt libraries, it still tells me to pip install pyOpenSSL
)
Any ideas about the Flutter side or publishing Django side for https would be awesome. However, solving the issue of making the Flutter side work with http would be more educational and practical for me.