flutter 应为标识符,应为查找“)”错误

rggaifut  于 2023-11-21  发布在  Flutter
关注(0)|答案(2)|浏览(139)

我是初学者编码器,我不明白如何解决这个错误

Future<http.Response> fetchData(String query) async {
    return  http.post(
      Uri.parse('https://laravelsyd-fypfinalver.herokuapp.com/getBusService'),

      headers: <String, String>{
        'Content-Type': 'application/json; charset=UTF-8',
      },
      body: { 
        jsonEncode({'bus_stop_id': busCode})
      },
        if (response.statusCode == 200) {
          final List<dynamic> data = json.decode(response.body);
          dataList = List<Map<String, dynamic>>.from(data);
          setState(() {// Update the state to trigger a rebuild with the fetched data
             dataList = List<Map<String, dynamic>>.from(data);
          },);
        } else {
          print (response.statusCode);
        }
        );
  }

字符串
错误:应为标识符。应为查找“)”
我应该把如果检查状态码?我需要做新的类?
我试着重新排列代码

ecbunoof

ecbunoof1#

请尝试此代码

Future<http.Response> fetchData(String query) async {
var response = await http.post(
    "https://laravelsyd-fypfinalver.herokuapp.com/getBusService",
    headers: <String, String>{
      'Content-Type': 'application/json; charset=UTF-8',
    },
    body: jsonEncode({'bus_stop_id': busCode}));

if (response.statusCode == 200) {
  final List<dynamic> data = json.decode(response.body);
  dataList = List<Map<String, dynamic>>.from(data);
  setState(
    () {
      // Update the state to trigger a rebuild with the fetched data
      dataList = List<Map<String, dynamic>>.from(data);
    },
  );
} else {
  print(response.statusCode);
}}

字符串

lb3vh1jj

lb3vh1jj2#

试试这段代码,希望能解决你的问题。

Future<http.Response> fetchData(String query) async {
final response = await http.post(
      Uri.parse('https://laravelsyd-fypfinalver.herokuapp.com/getBusService'),

      headers: <String, String>{
        'Content-Type': 'application/json; charset=UTF-8',
      },
      body: { 
        jsonEncode({'bus_stop_id': busCode})
      },
       
        );
return response;
  }

字符串

相关问题