Home > Mobile >  pass multiple params from flutter to node
pass multiple params from flutter to node

Time:07-22

I need to pass multiple query params from flutter to node. Do you know the best way? I need to pass the city, date, location.

Here is my dart file

  Future<Appointment> searchSingleAppointment({
    required BuildContext context,
    required String city,
    required String date,
    required String location,
  }) async {
    Appointment appointment = Appointment(id: '', city: '', date: '', location: '', appointmentStatus: '', queue: 0);
    try {

      http.Response res =
          await http.get(Uri.parse('$uri/appointments/search/'), 
          headers: {
        'Content-Type': 'application/json; charset=UTF-8',
        // 'x-auth-token': userProvider.user.token,
      });

      httpErrorHandle(
        response: res,
        context: context,
        onSuccess: () {
          appointment = Appointment.fromJson(res.body);
        },
      );
    } catch (e) {
      showSnackBar(context, e.toString());
    }
    return appointment;
  }
}

and here's my node js file. I need those params so I can use them in my find()

appointmentRouter.get("/appointments/search/", async (req, res) => {    
    console.log(req.params);
    
try {
    const appointment = await Appointment.find();

    res.json(appointment);
} catch (e) {
    res.status(500).json({ error: e.message });
    }
});

CodePudding user response:

Did you make sure the socket is connected or not?

CodePudding user response:

Use queryParameters. Here is the example:

final queryParameters = {'search': 'blue', 'limit': '10'};
final uri = Uri.parse('https://example.com/page/').replace(queryParameters: queryParameters);
print(uri); // https://example.com/page/?search=blue&limit=10
  • Related