Ahmadre / FlutterIconPicker

An adaptive comprehensive IconPicker for Flutter
MIT License
112 stars 76 forks source link

Box Icons getting displayed like 'X' marks #10

Closed pranjal-joshi closed 4 years ago

pranjal-joshi commented 4 years ago

Hello, In my use case, FlutterIconPicker will help the user to pick an icon, then this icon info is saved in some class. This class will be serialized to JSON and will be Stored/Retrieved from SharedPreferences as a configuration data. While loading from shared preference, I get the iconCode correct, but after using it as Icon(IconData(iconCode)), I get a strange output as shown in following image: Screenshot_2020-08-04-22-19-41-100_com example SMART Note: Here the last item is added manually in the list, However, the first 3 items are fetched from SharedPreference and no exception has been thrown during fetching and populating the data!

// Code Snippet - Deserializing data holding class
SmartRoomData.fromJsonString(String rawJson) {
    try {
      rawJson = rawJson.replaceAll('\'', '\"');
      Map<String, dynamic> json = jsonDecode(rawJson);
      name = json['name'];
      icon = IconData(int.parse(json['icon']));
      smartIds = json['smartIds'];
    } catch (e) {
      print(e);
    }
  }

// Code Snippet - Serializing Data holding class
Map<String, dynamic> toJson() {
    return {
      'name': name,
      'icon': icon.codePoint.toString(),
      'smartIds': smartIds.toList(),
      'type': type,
    };
  }

  String toJsonString() {
    return jsonEncode(toJson());
  }
Ahmadre commented 4 years ago

Thank you @pranjal-joshi for using my package đź’™.

At first I have good news for you: You don't have to worry about Serialization :).

This package is handling and providing this for you.

Look deeper in the readme and you'll find this:

iconDataToMap​(iconData)

Use that method to convert you IconData object into savable json for your shared prefs.

After that, if you want to load it from shared prefs use:

mapToIconData(map)

best regards :)

pranjal-joshi commented 4 years ago

Thank you @pranjal-joshi for using my package đź’™.

At first I have good news for you: You don't have to worry about Serialization :).

This package is handling and providing this for you.

Look deeper in the readme and you'll find this:

iconDataToMap​(iconData)

Use that method to convert you IconData object into savable json for your shared prefs.

After that, if you want to load it from shared prefs use:

mapToIconData(map)

best regards :)

Thanks for the quick help! I'll go through the docs and will let you know :)

pranjal-joshi commented 4 years ago

@Ahmadre I found that in my serialization method, I missed fontFamily property of iconData which was resulting as null while deserializing was the cause of this issue, After implementing a way to handle fontFamily, Now the issue is resolved!