title: Navigation in flutter without context
body: <p>I created a service folder and made a file in it called request. dart, here I intend to place all requests I make into a class called AuthService, with the login request below I want to be able to navigate to the home screen once response.statusCode == 200 or 201 but I am unable to do that because navigation requires a context and my class is neither a Stateful nor Stateless widget, is there any way I can navigate without the context??</p>
  <pre><code>import 'dart:convert';
  import 'package:http/http.dart' as http;
  import 'package:shared_preferences/shared_preferences.dart';
  import 'package:flutter/material.dart';
  
  class AuthService {
  
    login(email, password) async {
      SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
  
      if (email == &quot;&quot; &amp;&amp; password == &quot;&quot;) {
        return;
      }
  
      try {
        Map data = {'email': email, 'password': password};
  
        var jsonResponse;
        var response = await http
            .post('https://imyLink.com/authenticate', body: data);
        if (response.statusCode == 200 || response.statusCode == 201) {
  
  //I want to navigate to my home screen once the request made is successful
  
          jsonResponse = json.decode(response.body);
          if (jsonResponse != null) {
            await sharedPreferences.setString(&quot;userToken&quot;, jsonResponse[&quot;token&quot;]);
            var token = sharedPreferences.getString(&quot;userToken&quot;);
            print('Token: $token');
            print(jsonResponse);
            print(&quot;Login successful&quot;);
          }
        } else {
          print(response.statusCode);
          print('Login Unsuccessful');
          print(response.body);
        }
      } catch (e) {
        print(e);
      }
  }
  </code></pre>