import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:http/http.dart' as http; class SignIn with ChangeNotifier { String cookie; Future login(String url, String email, String password) async { String urlApi = url + '/api/v1/login'; Map headers = { "X-Requested-With": "XMLHttpRequest", "Content-Type": "application/json", }; var body = json.encode({"login": email, "password": password}); final response = await http.post(urlApi, headers: headers, body: body); if (response.statusCode == 200) { // If the server did return a 200 OK response, // then parse the JSON. print(response.headers['set-cookie']); cookie = response.headers['set-cookie']; //TODO : return http.get + company_choice_screen root recoverUserData(urlApi); // If the server did not return a 200 OK response, // then throw an exception. //TODO: error message ? } // final responseJson = json.decode(response.body); } Future recoverUserData(String url) async { Map headers = {"X-Requested-With": "XMLHttpRequest","Cookie":cookie}; final response = await http.get(url, headers: headers); if (response.statusCode == 200) { // If the server did return a 200 OK response, // then parse the JSON. print(response.headers['datas']); } else { // If the server did not return a 200 OK response, // then throw an exception. } // final responseJson = json.decode(response.body); // // print(responseJson); } }