Save Data to Shared Preferences in Flutter | Day 08 -

Поділитися
Вставка
  • Опубліковано 8 лют 2021
  • Kilo Loco shows you how build settings page and save all the selected values to Shared Preferences. In this tutorial, you will learn about the different types of List Tiles, converting enums to and from savable states, and retrieving stored data from shared preferences.
    ** Show Notes and Links **
    Project Files:
    github.com/Kilo-Loco/30DaysOf...
    Kilo Loco on Social Media:
    www.kiloloco.com
    Discord - / discord
    Twitter - / kilo_loco
    Instagram - / kilo_loco
    #flutter #dartlang #30DaysOfFlutter

КОМЕНТАРІ • 42

  • @adamhowley8037
    @adamhowley8037 Рік тому

    Just stumbled upon your channel. Love the length of these videos. Great explanations. Thanks!

  • @aldrinalainroncocarrillo8076
    @aldrinalainroncocarrillo8076 2 роки тому +1

    Hello kilo loco, greetings from Colombia, I just want to leave you my most sincere thanks and respect for making such high quality content, especially I take great advantage of your flutter publications, since it is what I am currently applying, thank you very much friend and God bless

  • @kanyevest
    @kanyevest 2 роки тому +2

    it's interesting going through these and implementing null safety along the way too

  • @RandalLSchwartz
    @RandalLSchwartz 3 роки тому +3

    You can store the enums as String or ListString as the toString of the values, and restore them using this mapping, as demonstrated here in a dartpad snippet:
    void main() {
    var inStorage = Language.Flutter.toString();
    var string2Language = Language.values.asMap().map((k,v) => MapEntry("$v",v));
    var inProg = string2Language[inStorage];
    print(inProg == Language.Flutter);
    }
    enum Language { Flutter, Dart, JavaScript, Perl }

  • @RandalLSchwartz
    @RandalLSchwartz 3 роки тому

    And I want to re-emphasize... your videos are great! Thank you for doing them!

  • @jamilurrehmanamini4878
    @jamilurrehmanamini4878 2 роки тому

    best video please continue with flutter videos Thanks in advance subscribed

  • @masihreyhani3910
    @masihreyhani3910 3 роки тому

    Amazing stuff! Thank you so much.

  • @ashwantariq
    @ashwantariq 2 роки тому

    great video man thank you

  • @furkanfrk5179
    @furkanfrk5179 2 роки тому

    Thank you very clear !

  • @antoniodb9988
    @antoniodb9988 Рік тому

    Bravo!👌

  • @Praveenmgupta
    @Praveenmgupta 2 роки тому +2

    Thanks a lot for the tutorials, I'm enjoying and learning a lot. Can you please make a video on backing up & restoring data stored in sqflite and also exporting and importing of data through csv files.

  • @Marvelus2009
    @Marvelus2009 3 роки тому +1

    this series helped me a lot with writing one of my SwiftUI apps in flutter for android, I learned so much, and it is only day 8, I'm actually excited now, thank you sir.

    • @bradykaiser3540
      @bradykaiser3540 2 роки тому

      i guess Im kinda randomly asking but do anyone know a good website to stream new tv shows online ?

    • @guillermotrace4391
      @guillermotrace4391 2 роки тому

      @Brady Kaiser Meh try Flixportal. just google after it:P -guillermo

    • @bradykaiser3540
      @bradykaiser3540 2 роки тому

      @Guillermo Trace Thanks, I went there and it seems like they got a lot of movies there :D I really appreciate it!!

    • @guillermotrace4391
      @guillermotrace4391 2 роки тому

      @Brady Kaiser Happy to help :D

  • @RandalLSchwartz
    @RandalLSchwartz 3 роки тому +1

    And thank you for TextButton!

  • @thrillclip
    @thrillclip 2 роки тому

    kudos!!

  • @RandalLSchwartz
    @RandalLSchwartz 3 роки тому +2

    Best to have those key strings as const String then. :)

  • @AbdullahHattab
    @AbdullahHattab Рік тому

    Thanks for this lesson, I was wondering if I change the values too many times do they keep the old records or do they overwrite them? And if it is kept and repeated, how can I delete the old values, or in other words, how can I replace the value according to the key? Thanks again.

  • @Andy_Druws
    @Andy_Druws 2 роки тому +1

    Thanks so cool video ) Ez like ^) Uh Models Uh.

  • @sangputuokasusila9506
    @sangputuokasusila9506 2 роки тому

    bro, how do you get into the database?

  • @learningcurious5845
    @learningcurious5845 2 роки тому

    after converting to apk release file installing on an android phone not working not retreiving the API. but working fine in emulator. what is the reason anybody??

  • @mazharimam9216
    @mazharimam9216 2 роки тому

    y we didn't had any parameter in onchanged in checkboxlist

  • @wareeffallatah1335
    @wareeffallatah1335 Рік тому

    I am new to flutter, what is “dirty” in his code

  • @luckimeluckimeapp5709
    @luckimeluckimeapp5709 3 роки тому +1

    Thanks a lot for the tutorial, Can you please refactor the code to use a state management library like Riverpod or Bloc instead of using SetState? thanks

    • @Kilo_Loco
      @Kilo_Loco  3 роки тому +3

      I'll be covering state management in the coming weeks 😉

  • @Kuuuhrizz
    @Kuuuhrizz 2 роки тому

    I had a problem importing shared_preferences. When I added the import 'package:shared_preferences/shared_preferences.dart'; into my code, the app crashes and 60% of dart started eating my cpu.

    • @Kuuuhrizz
      @Kuuuhrizz 2 роки тому +1

      Update: Flutter released version 2.5 and upgrading to it made things work normally again.

  • @braindroid9657
    @braindroid9657 2 роки тому +2

    idk why m getting an error at newValue... it doesn't show anything except red line ... any idea ??

    • @raomuhammadusama9244
      @raomuhammadusama9244 2 роки тому +2

      It's an object error. Just change it from newValue to newValue as Gender.

  • @marcinbiaasek9776
    @marcinbiaasek9776 2 роки тому

    4:15 lol ... "other"

  • @hoekbrwr
    @hoekbrwr 3 роки тому +3

    I have a problem with null safety! You tell at 27:20 that programmingLanguages may be null, but do not handle null safety. You just go on and leave the subject unhandled. When I start my app it gives me a null object at the .map Like this:
    Exception has occurred.
    NoSuchMethodError (NoSuchMethodError: The method 'map' was called on null.
    Receiver: null
    Tried calling: map(Closure: (String) => ProgrammingLanguage))
    At least it must start with an empty List of Strings.
    Can I create a dummy var with empty List of Strings? Obvious not I get runtime error when doing this
    const emptyLanguage = [];
    final programmingLanguagesIndicies =
    preferences.getStringList('programmingLanguages') ?? emptyLanguage;
    I am stuck! Anyone who can explain to overcome this and come from the ground up?

    • @Kilo_Loco
      @Kilo_Loco  3 роки тому +6

      This video series doesn't cover null safety as it was not on stable at the time and is still currently an opt in feature. You may be able to solve the problem by using the ? in a few places to accommodate for null safety, but I haven't used it yet personally in dart. If I had to guess, the code should look something like this:
      final programmingLanguages = programmingLanguagesIndicies?
      .map((stringIndex) => ProgrammingLanguage.values[int.parse(stringIndex)])
      .toSet()
      ?? Set()
      The idea here being that the programmingLanguagesIndicies is nullable and if the value is null, then return an empty Set

    • @chakroid13
      @chakroid13 3 роки тому

      @@Kilo_Loco No its not working ..

    • @Build_the_Future
      @Build_the_Future 3 роки тому

      if you are talking about the null safety in the settings, then try using the "??" like this. isEmployed: isEmployed ?? true); username: username ?? "it's null",

    • @tuann2507
      @tuann2507 2 роки тому +3

      Try to click the continue debug button while debugging, then select the checkbox option in your simulator, then save. That's what I fix. Hopefully, it can help. I think the first run there is no saved data yet, so it catches the empty set and popup the warning. Follow my step, hope next time can run normally. If any better ways to fix it, please let me know. Cheers

    • @mashilheiba1nm720
      @mashilheiba1nm720 2 роки тому

      Did you found the solution? i'm also stuck in here