1

I created an flutter app with a Laravel back-end. I build the APK file for my app and installed it on to my mobile phone and connected my mobile phone to the same network as my computer with WiFi (my WiFi adapter is the same network as my computer).

When I try to use my web browser to connect my Laravel app (http://192.168.10.22:8000/api/polls), it shows expected results (for example, the poll titles). But when I try to use my app, I get empty list. Here is my code:

Future<void> fetchPolls() async {
    print('Fetching polls...');
    final response =
        await http.get(Uri.parse('http://192.168.10.22:8000/api/polls'));

    if (response.statusCode == 200) {
      print('Response body: ${response.body}'); // Log the response body
      setState(() {
        polls = jsonDecode(response.body);
        print('Polls: $polls'); // Log the polls list
      });
    } else {
      print(
          'Failed to load polls: ${response.statusCode}'); // Log the error status
      throw Exception('Failed to load polls');
    }
  }

I tried the same using Postman, http://192.168.10.22:8000/api/polls - It is ok.

Here are the things I've tried:

  • Added local.properties : minSdkVersion=30 to make my app compatible with android 11
  • Created rule to access Laravel app via 8000 port.
  • php artisan serve --host=0.0.0.0 --port=8000 to bind the server to 0.0.0.0
1

1 Answer 1

3

HTTP without SSL (HTTPS) are disabled by default in Flutter.

Just add usesCleartextTraffic flagfor debug builds in AndroidManifest.xml

<application android:usesCleartextTraffic="true"/>

Follow this link for more info: https://docs.flutter.dev/release/breaking-changes/network-policy-ios-android

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.