Android App Development
iOS App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 184.108.40.206 release ready!
Owner and Founder. Opencart
Hi everyone, this blog is about Shared Preferences using dart.
Here we will make a flutter app, in this example, we will make a login app to save data and as a result it will manage login sessions for users.
Users can enter login details and login into App and will be redirected to the home screen. Next time when the user comes in, app session is managed and as a result, it will directly redirect to the home page.
If you will logout from the home page by pressing the logout button. Then the user will be logged out and again redirect to the login page and will restart the session.
So let’s make an easy example using the shared preferences.
Shared Preferences is a plugin for flutter apps. It is a local database that we use to store small data for the app. As we know, we can store data in shared preference in key-value pair form.
First of all, we need to add package dependencies to pubspec.yaml file.
First dependency for shared preferences
Second dependency for showing status of session on login logout actions.
Now we have to create two files
main.dart file for the login screen and a homepage.dart file for the Homepage screen
In this, we did our login page code and save the status of the session using shared preference after pressing the login button and navigate to the homepage page because the session status will logged in.
In this, we did code for the homepage.dart and also provided a logout button to update the session status using shared preferences.
Here are images of login screen and homepage
I hope this blog will help you to learn about Shared Preferences and you will be able to implement them.
Happy Learning ✍️
Your email address will not be published. Required fields are marked*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
Great Product, Great Team, and Great Support Service. And if you want to add more features to the product, they can submit any idea that comes to your mind. They really care about their clients and we are really happy and honored to deal with Webkul.
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.