title: Bearer token request http flutter
body: <p>I need to send my token for my API.
  I save my token in SharedPreferences and I can recupered this.
  My API need one, with the Bearer but how do ? </p>
  
  <p>I tested with Authorization, Http etc.</p>
  
  <p>Methods To save in SP</p>
  
  <pre><code>Future&lt;bool&gt; setToken(String value) async {
      final SharedPreferences prefs = await SharedPreferences.getInstance();
      return prefs.setString('token', value);
    }
  
    Future&lt;String&gt; getToken() async {
      final SharedPreferences prefs = await SharedPreferences.getInstance();
      return prefs.getString('token');
    }
  
    Future&lt;Candidate&gt; candidateAuth({Map map}) async {
      String url = 'http://10.0.2.2:3000/v1/api/auth/candidate';
      await http
          .post(url,
              headers: {
                'Content-type': 'application/json',
                'Accept': 'application/json'
              },
              body: jsonEncode(map))
          .then((response) {
        if (response.statusCode == 201) {
          token = Candidate.fromJson(json.decode(response.body)).token;
          Candidate().setToken(token);
          return Candidate.fromJson(json.decode(response.body));
        } else {
          throw Exception('Failed auth');
        }
      });
    }
  }
  </code></pre>
  
  <p>My API Call :</p>
  
  <pre><code>
  Future&lt;List&lt;Theme&gt;&gt; getThemes() async {
      String url = 'http://10.0.2.2:3000/v1/api/theme';
      String token;
      Candidate().getToken().then((value) {
        token = value;
      });
      final response = await http.get(url, headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Authorization': 'Bearer $token',
      });
      print('Token : ${token}');
      print(response);
  
      if (response.statusCode == 200) {
        List themesList = jsonDecode(response.body);
        List&lt;Theme&gt; themes = [];
        for (var themeMap in themesList) {
          themes.add(Theme.fromJson(themeMap));
        }
        return themes;
      } else {
        throw Exception('Failed to load themes');
      }
    }
  
  </code></pre>
  
  <p>My API return error 401 : unauthorized</p>