Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
196 views
in Technique[技术] by (71.8m points)

Auto-generate class and member from json file in Flutter

I have a simple json file like below. This is fixed in the project.

{
    "en": "English",
    "es": "Espa?ol",
    "fr": "Fran?ais"
}

My question is, is it possible to do a auto-generate work to create a class with members which return the value of each key? The result of the auto-generate can be similar to below example. So every time I add new key and value to the json file, this class will generate or update that new item into it.

class JsonHelper {
    static String get en => json['en'];

    static String get es => json['es'];

    static String get fr => json['fr'];
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

you can use this site for Auto-generate class in Flutter:

https://app.quicktype.io/?share=pxoAci2ZiiPtLyjXaYhD

another way is using Auto-generator package of npm


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...