aboutsummaryrefslogtreecommitdiff
path: root/lib/models/data/settings_data_class.dart
blob: e8cd60427ca6d7d8bfdcea7811ed61fd6c371695 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import 'dart:convert';

import 'package:kulinar_app/util/storage_handler.dart';

class SettingsData {
  static Map<String, String> settings = {
    "showPhotos": "0",
    "photoSource": "1",
    "serverURL": "",
  };

  static Future<void> save() async {
    await StorageHandler.store("settings", encode());
  }

  static Future<void> load() async {
    decode(await StorageHandler.fetch("settings") ?? "{}");
  }

  static String encode() {
    return jsonEncode(settings);
  }

  static void decode(String data) {
    final _result = jsonDecode(data);

    if (_result.isEmpty) return;

    _result.forEach((key, value) {
      settings[key] = value;
    });
  }
}