You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter app无法从Laravel后端API获取数据求助

Flutter调用Laravel接口返回空列表问题

我开发了一个基于Laravel后端的Flutter应用,已构建APK并安装在手机上,且手机与电脑处于同一WiFi网络。通过浏览器访问Laravel接口http://192.168.10.22:8000/api/polls可正常获取投票数据,Postman测试该接口也正常,但应用中调用该接口却返回空列表。

以下是我的代码:

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');
    }
  }

我已尝试的解决方法:

  • 在local.properties中设置minSdkVersion=30以适配Android 11
  • 创建规则允许通过8000端口访问Laravel应用
  • 使用php artisan serve --host=0.0.0.0 --port=8000将服务器绑定到0.0.0.0

内容的提问来源于stack exchange,提问作者Pham Xuan Nguyen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 12:07:07