Skip to content

This Flutter code defines a login page that makes use of the shared_preferences and http packages to manage user authentication.

Notifications You must be signed in to change notification settings

PradeepTheDeveloper/login_page_http_shared_preference

Repository files navigation

This Flutter code defines a login page that makes use of the shared_preferences and http packages to manage user authentication. The user enters their email and password, which are then sent to the specified API using an HTTP post request. If the login is successful, the API sends back a response containing an authentication token. This token is stored in the app's SharedPreferences so that the user doesn't have to log in again when the app is reopened.

The page is defined as a stateful widget with a boolean _isLoading flag, which is used to show a loading indicator while waiting for the API response. The page includes two TextFormField widgets for the email and password input fields, and an ElevatedButton for the sign-in action. The onPressed function of the sign-in button checks that the email and password fields are not empty and then calls the signIn function to make the API call.

The signIn function uses the http package to make an HTTP POST request to the specified API endpoint, passing in the user's email and password. If the response from the server is successful, the response body is parsed as a JSON object, and the authentication token is stored in the app's SharedPreferences. The Navigator then pushes a new page onto the stack, removing the login page so that the user can continue using the app. If the response is unsuccessful, the _isLoading flag is set to false, and an error message is printed to the console.

Overall, this code provides a simple example of implementing user authentication in a Flutter app using shared_preferences and HTTP.# login_page_http_shared_preference

login_screen_http_shared_preference

About

This Flutter code defines a login page that makes use of the shared_preferences and http packages to manage user authentication.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published