Saving Data in Flutter

Jan 31 2024 · Dart 3, Flutter 3.10, Visual Studio Code

Part 2: Use SharedPreferences & Secure Storage

08. Challenge: Add a Field

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 07. Connect the User Interface to the Data (Part 2) Next episode: 09. Using flutter_secure_storage

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

Challenge

Welcome to the second challenge for this course. This time, it actually involves writing some code. But the good news is that if you’ve followed along, you should have no problem completing this.

Solution

So here is the solution for this challenge:

static const String _showDate = 'showDate';   
bool getShowDate() { 
  return _preferences.getBool(_showDateKey) ?? true; 
} 
Future<bool> setShowDate(bool showDate) async { 
  final result = await _preferences.setBool(_showDateKey, showDate); 
  return result; 
} 
bool _showDate = false; 
_showDate = prefs.getShowDate();