• Courses
  • YouTube
  • Dev News
  • Technology
  • Blogs
  • Flutter Jobs
  • Contact
    • About Us
    • RegisterLogin
    Navoki
    • Courses
    • YouTube
    • Dev News
    • Technology
    • Blogs
    • Flutter Jobs
    • Contact
      • About Us
    • RegisterLogin

      Flutter

      • Home
      • Blog
      • Flutter
      • Flutter shared preference
      Imageedit 4 8537261519 | Flutter Shared Preference

      Flutter shared preference

      • Posted by Shivam Srivastava
      • Categories Flutter
      • Date September 19, 2019
      • Comments 0 comment
      Spread the love

      Introduction

      In this blog I show you how to use Shared Preference in your flutter project, I am sure understood working of shared preference if still, you have any question in your mind then continue to read this blog your all doubts get resolve.

      Shared Preference?

      In mobile application development have functionality for storing the data, Shared Preference is also one of the ways for storing the data.
      It has a key-value pair for storing and retrieve the data we can say that Shared Preference is similar to maps in the collection framework.
      Shared preference doesn’t need any database for storing the data and also we don’t have need any query to retrieve the data from it. Shared Preference objects share common memory locations like static members so that we can store and retrieve the data from different objects.

      Start

      1. Create a flutter project
      2. add dependency shared_preferences: <latest_version> in pubspec.yaml file

      import

      import 'package:shared_preferences/shared_preferences.dart';
      SharedPreferences prefs;

      Save data in Shared Preference

        void saveData(String data)async{
      
          prefs=await SharedPreferences.getInstance();
         
          prefs.setString("setString", "save string");
          prefs.setBool("setBool", false);
          prefs.setDouble("setDouble", 20.5);
          prefs.setInt("setInt", 20);
          prefs.setStringList("setStringList", ['value1','value2','value3']);
        }

      Retrieve data from Shared Preference

          retrieveData() async {
          final sharedPreferences = await SharedPreferences.getInstance();
      
          String getString = prefs.getString("setString");
          bool getBool = prefs.getBool("setBool");
          double getDouble = prefs.getDouble("setDouble");
          int getInt = prefs.getInt("setInt");
          List<String> getList = prefs.getStringList("setStringList");
        }

      Delete all data from Shared_Preference

        void clear()async{
          prefs=await SharedPreferences.getInstance();
          prefs.clear();
        }

      Now you can simply call these functions as you need and use shared preference in your project.

      Bookmark(1)

      Please login to bookmark

      Continue with Google
      0

      Tag:flutter secure storage, flutter secure storage example, flutter shared_preferences example, flutter sharedpreferences github, flutter sharedpreferences save object

      • Share:
      author avatar
      Shivam Srivastava

      Mobile Solution [email protected], Android and Flutter Dev, Dart ,Founder of @Navoki, Instructor

      Previous post

      Make your first Flutter Web app and Publish [2019]
      September 19, 2019

      Next post

      IIOT 2019 in Delhi
      September 23, 2019

      You may also like

      everything-about-flutter-3-in-google-i-o-2022 navoki.com
      Everything about Flutter 3 in Google I/O 2022
      12 May, 2022
      Flutter-Web-CORS-Error-SOLVED-Navoki.com
      [SOLVED] Flutter Web CORS Error
      4 May, 2022
      How Video Call works in Flutter
      How Incoming Video Call Notification works in Flutter
      15 April, 2022

      Leave A Reply Cancel reply

      You must be logged in to post a comment.


      Categories

      • Android
      • Dart
      • Dart Server
      • Dart Web
      • Developers
      • Flutter
      • Flutter Desktop
      • Flutter Mobile
      • Flutter Web
      • Fuchsia
      • Go Lang
      • Technology
      • Uncategorized

      Recent Post

      • Everything-About-Flutter-3-In-Google-I-O-2022 Navoki.comEverything about Flutter 3 in Google I/O 2022
      • Flutter-Web-Cors-Error-Solved-Navoki.com[SOLVED] Flutter Web CORS Error
      • How Video Call Works In FlutterHow Incoming Video Call Notification works in Flutter

      Subscribe Now

       

      Recent Courses

      Single And Multi Selection Listview In Flutter

      Single and Multi Selection ListView in Flutter

      Go Installation And Variables

      Go Installation and Variables

      List In Dart Programming Language

      List in Dart Programming language

      Variables In Dart Programming Language

      Variables in Dart Programming language

      View All

      DON’T MISS
      FLUTTER UPDATES

      Be the first to know when our blog is published.

      flutter-mobile-mockup

      Check your inbox or spam folder to confirm your subscription.

      Contact

      •   Navoki Technologies Pvt. Ltd.
        JMD Megapolis , Sector 48, Gurugram, Haryana 122018

      Company

      • About Us
      • Blogs
      • Contact
      • Privacy policy
      • Terms & Condition

      Useful Links

      • Courses
      • Youtube
      • Dev News

      Mobile

      Click and Get started in seconds

      "Navoki" is a registered trademark of Navoki.com ® 2020–2030 Navoki Technologies Pvt Ltd.

      • Terms & Condition

      Login with your site account

      Continue with Google

      By "Sign in” above to accept Navoki’s Terms of Service & Privacy Policy.

      Not a member yet? Register now

      Register a new account

      Continue with Google

      By "Sign Up” above to accept Navoki’s Terms of Service & Privacy Policy.

      Are you a member? Login now

      We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkPrivacy policy