title: How to pass/send data received from an api call in a particular screen(Login screen) to a seperate screen(Home Screen)using provider?
body: <p>The control flow is as follows</p>
  <p>I have one function that makes an api call that returns a string accesscode(logUserin()).</p>
  <p>Then the second function (getUserdetailsFromApi()) gets called that takes in input which is the response of the first function call. The second function call returns a map that contains user details.</p>
  <p>The second function gets called inside the first function and the first function gets called when the user clicks login button.</p>
  <p>My issue is that i cant create a seperate class that extends changenotifier to run the second function because that class cannot receive the data that gets returned from the first function call(loggedinUseraccessCode). Therefore i an unable to use provider to send the data received from the second function call to the Homescreen of my app.</p>
  <p>Heres my stateful login class</p>
  <pre><code>class LoginPage extends StatefulWidget {
    static const String id = 'Loginpage';
    var loggedInUserAccessCode;
  
    @override
    State&lt;LoginPage&gt; createState() =&gt; _LoginPageState();
  }
  
  class _LoginPageState extends State&lt;LoginPage&gt; {
    final _formKey = GlobalKey&lt;FormState&gt;();
    TextStyle defaultStyle = const TextStyle(color: Colors.grey, fontSize: 15.0);
    TextStyle linkStyle = const TextStyle(color: Colors.blue);
    bool showSpinner = false;
  
    String email = '';
  
    String password = '';
  
    String? loginErrormessage;
  
    var loggedinUserRefreshCode;
  
    var userFirstname;
  
    var userLastname;
  
    var userEmail;
  
  
    void startSpinning() {
      setState(() {
        showSpinner = true;
      });
    }
  
    void stopSpinning() {
      setState(() {
        showSpinner = false;
      });
    }
  
    void getUserDetailsFromApi() async {
      var headers = {'Authorization': 'Bearer ${widget.loggedInUserAccessCode}'};
      var request = http.Request(
          'GET', Uri.parse('link hidden'));
  
      request.headers.addAll(headers);
  
      http.StreamedResponse response = await request.send();
  
      if (response.statusCode == 200) {
        var responseString = await response.stream.bytesToString();
        final decodedResult = jsonDecode(responseString);
        userFirstname = decodedResult['first_name'];
        userLastname = decodedResult['last_name'];
        userEmail = decodedResult['email'];
      
      } else {
        print(response.statusCode);
      }
    }
  
    void logUserIn() async {
      try {
        var request = http.MultipartRequest(
            'POST', Uri.parse('link hidden for privacy'));
        request.fields.addAll({
          'email': email,
          'password': password,
        });
        http.StreamedResponse response = await request.send();
  
        if (response.statusCode == 200) {
          var responseString = await response.stream.bytesToString();
          final decodedResult = jsonDecode(responseString);
          widget.loggedInUserAccessCode = decodedResult['access'];
          loggedinUserRefreshCode = decodedResult['refresh'];
          stopSpinning();
          Navigator.pushReplacementNamed(context, MainScreen.id);
          ScaffoldMessenger.of(context).showSnackBar(SuccessLoginSnackbar);
        } else if (response.statusCode == 401) {
          var responseString = await response.stream.bytesToString();
          final decodedResult = jsonDecode(responseString);
          setState(() {
            loginErrormessage = decodedResult['detail'];
          });
          stopSpinning();
        }
      } catch (e) {
        setState(() {
          stopSpinning();
        });
      }
    }
  
    @override
    Widget build(BuildContext context) {
      return SafeArea(
        child: ModalProgressHUD(
          inAsyncCall: showSpinner,
          child: Scaffold(
            backgroundColor: Colors.white,
            body: ListView(
                scrollDirection: Axis.vertical,
                padding: const EdgeInsets.all(10.0),
                children: [
                  addverticalSpacing(5),
                  showAlert(),
                  Form(
                    key: _formKey,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      crossAxisAlignment: CrossAxisAlignment.stretch,
                      children: [
                        addverticalSpacing(100),
                        const Padding(
                          padding: EdgeInsets.symmetric(horizontal: 8.0),
                          child: Text(
                            'Login',
                            style: kboldtextstyleblack,
                          ),
                        ),
                        addverticalSpacing(100),
                        TextFormField(
                          autovalidateMode: AutovalidateMode.onUserInteraction,
                          validator: emailvalidator,
                          onChanged: (value) {
                            email = value;
                          },
                          decoration: const InputDecoration(
                            hintText: 'Email address',
                            contentPadding: EdgeInsets.symmetric(
                                vertical: 10.0, horizontal: 20.0),
                          ),
                        ),
                        addverticalSpacing(40),
                        TextFormField(
                          validator: passwordValidator,
                          obscureText: true,
                          obscuringCharacter: '*',
                          autovalidateMode: AutovalidateMode.onUserInteraction,
                          onChanged: (value) {
                            password = value;
                          },
                          decoration: const InputDecoration(
                            suffixIcon: Icon(Icons.visibility),
                            hintText: 'Password',
                            contentPadding: EdgeInsets.symmetric(
                                vertical: 10.0, horizontal: 20.0),
                          ),
                        ),
                        addverticalSpacing(100),
                        ReusableButton(const Text('Log in'), () async {
                          if (_formKey.currentState!.validate()) {
                            startSpinning();
                            logUserIn();
                          }
                        }),
                        addverticalSpacing(30),
                        Center(
                          child: RichText(
                            text: TextSpan(children: &lt;TextSpan&gt;[
                              TextSpan(
                                  text: 'Forgot pasword ?',
                                  style: linkStyle.copyWith(fontSize: 15),
                                  recognizer: TapGestureRecognizer()
                                    ..onTap = () {}),
                            ]),
                          ),
                        ),
                        addverticalSpacing(5),
                        Center(
                          child: RichText(
                            text: TextSpan(children: &lt;TextSpan&gt;[
                              TextSpan(
                                text: 'Don\'t have an account yet ? ',
                                style: defaultStyle,
                              ),
                              TextSpan(
                                  text: 'Register',
                                  style: linkStyle,
                                  recognizer: TapGestureRecognizer()
                                    ..onTap = () {
                                      Navigator.pushReplacementNamed(
                                          context, RegistrationPage.id);
                                    }),
                            ]),
                          ),
                        ),
                        addverticalSpacing(5),
                      ],
                    ),
                  ),
                ]),
          ),
        ),
      );
    }
  }
  
  </code></pre>
  <p>I have tried using class constructors to achieve my aim but due to the structure of the app, i get an error from flutter. The mainscreen is a widget that has a bottom navigation that renders three widgets HomeScreen included.
  I am a new flutter developer so please exucuse any coding etiquete errors if found.</p>
  <p>I am considering just sending the loggedinuseraccesscode string from the loginscreen to the main screen then call the getUserdetailsfromApi function there and use a future builder to show the response as soon as it is ready but i would love it if a solution to this problem is available.</p>