Skip to content
| Marketplace
Sign in
Visual Studio Code>Extension Packs>Super Flutter UtilNew to Visual Studio Code? Get it now.
Super Flutter Util

Super Flutter Util

DASHUIBI

|
126 installs
| (0) | Free
功能:Json To Dart(json转dart模型)
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Super Flutter Util

该插件是 flutter 的辅助扩展,已添加的功能:

一、从剪切板获取 json 数据并转为 dart 数据模型

目前支持右键文件夹或右键代码编辑器添加模型,将会从剪切板中提取json数据,所有参数都为必填且非空:

{
   "title": "string",
   "age": 0,
   "duration": 10.1,
   "info": {
      "address": "string",
      "email": "string"
   },
   "phones": ["string"],
   "companys": [
      {
         "name": "string",
         "address": "string"
      }
   ]
}

转换后:

class TestModel {
  String title;
  int age;
  double duration;
  TestModelInfo info;
  List<TestModelCompanysItem> companys;

  TestModel({
    required this.title,
    required this.age,
    required this.duration,
    required this.info,
    required this.companys,
  });

  factory TestModel.fromJson(dynamic json) {
    if (json is! Map) json = <dynamic, dynamic>{};
    return TestModel(
      title: json['title'] is String ? json['title'] : '',
      age: json['age'] is int ? json['age'] : 0,
      duration: json['duration'] is double ? json['duration'] : 0,
      info: TestModelInfo.fromJson(json['info']),
      companys: json['companys'] is List ? json['companys'].map<TestModelCompanysItem>((item) => TestModelCompanysItem.fromJson(item)).toList() : [],
    );
  }

  Map<String, dynamic> toJson() => {
    'title': title,
    'age': age,
    'duration': duration,
    'info': info.toJson(),
    'companys': companys.map((item) => item.toJson()).toList(),
  };
}

class TestModelInfo ...
class TestModelCompanysItem ...
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft