Saving Data in Flutter

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

Part 3: Reading & Writing Files

17. Using JSON (Part 2)

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: 16. Using JSON (Part 1) Next episode: 18. Challenge: Implement The FileStat Object

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.

Now let’s use our class in our SPHelper class, in the sp_helper.dart file.

  static const String _settingsKey = 'settings'; 
AppSettings getAppSettings() { 
    final jsonString = _preferences.getString(_settingsKey); 
    return jsonString != null 
        ? AppSettings.fromJson(json.decode(jsonString) as Map<String, dynamic>) 
        : AppSettings( 
            listName: 'My list name', 
            calories: 2000, 
            showDate: true, 
            showFileSize: true); 
  } 
final settings = prefs.getAppSettings(); 
_listName = settings.listName; 
_calories = settings.calories; 
_showFileSize = settings.showFileSize; 
_showDate = settings.showDate; 
final settings = AppSettings( 
  listName: _listNameController.text, 
  calories: int.tryParse(_caloriesController.text) ?? 0, 
  showFileSize: _showFileSize, 
  showDate: _showDate); 
await prefs.setAppSettings(settings);