Save Data to Shared Preferences in Flutter | Day 08 -

Поделиться
HTML-код
  • Опубликовано: 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

  • @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 3 года назад +2

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

  • @adamhowley8037
    @adamhowley8037 Год назад

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

  • @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!

  • @ashwantariq
    @ashwantariq 2 года назад

    great video man thank you

  • @furkanfrk5179
    @furkanfrk5179 2 года назад

    Thank you very clear !

  • @RandalLSchwartz
    @RandalLSchwartz 3 года назад +2

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

  • @Praveenmgupta
    @Praveenmgupta 3 года назад +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.

  • @masihreyhani3910
    @masihreyhani3910 3 года назад

    Amazing stuff! Thank you so much.

  • @antoniodb9988
    @antoniodb9988 Год назад

    Bravo!👌

  • @jamilurrehmanamini4878
    @jamilurrehmanamini4878 3 года назад

    best video please continue with flutter videos Thanks in advance subscribed

  • @RandalLSchwartz
    @RandalLSchwartz 3 года назад +1

    And thank you for TextButton!

  • @thrillclip
    @thrillclip 2 года назад

    kudos!!

  • @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 3 года назад

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

    • @guillermotrace4391
      @guillermotrace4391 3 года назад

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

    • @bradykaiser3540
      @bradykaiser3540 3 года назад

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

    • @guillermotrace4391
      @guillermotrace4391 3 года назад

      @Brady Kaiser Happy to help :D

  • @Andy_Druws
    @Andy_Druws 2 года назад +1

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

  • @AbdullahHattab
    @AbdullahHattab 2 года назад

    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.

  • @marcinbiaasek9776
    @marcinbiaasek9776 2 года назад

    4:15 lol ... "other"

  • @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 😉

  • @mazharimam9216
    @mazharimam9216 2 года назад

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

  • @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.

  • @wareeffallatah1335
    @wareeffallatah1335 Год назад

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

  • @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??

  • @sangputuokasusila9506
    @sangputuokasusila9506 2 года назад

    bro, how do you get into the database?

  • @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.

  • @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