Hello, in this video, I am going to show you how to store key value pairs, you know internally on your device for local usage. So I've already got the code set up, I'm going to run through this with you, what I want you to do is make sure you've gone through the previous video we shouldn't be reading and writing to files. This is essentially an extension of that there are a few modifications to it, which you can check on the source code and I'm going to be covering that one. So basically, we're going to do is go from the million by two files code that we did in that video and adapted into this one. So the first thing that you want to do, go to the pub spec dot yamo and add the shared preferences. dependency Lake version as a Christmas video is 0.5 point one, two and unusual.
You can get the latest version by going to pub dartlang.org forces packages to share Here we go go to installing. And if we literally just copy down the do floater, get We don't even need to do it, you can just click date on it top to command. And okay, then you need to actually do the import, you don't need to do all the other crazy imports that you did for reading and writing to files. Okay, so what else have we got in here. So we've got a, you know, a few methods. So this one, initially just load the cat as you can see, this is you know, a lot simpler than the reading and writing files code.
So you have your load counter, you create a shared preferences. And this will, you know, be dynamic, whether it's on Android or iOS, your handle all of that in the back end, and you can reset state, which is just normal stuff. Then to actually get something just do press, get int and then name up. So this is the key, then you know this will return the actual value. And then if there isn't something then you just put zero there. And again, when you're incrementing it you go, you know, open it up, you do press dot get int, and status anything we are getting the value that you add to the key counter, adding one and then to setting just depressed offsetting the name of the key, the value and that is and obviously there is a button that increments but as you can see, it is extremely simple to utilize shared preferences only to have a goat that they have any questions, feel free to drop me a message.
And as usual, I look forward to seeing you in the next video.