网站首页 > 博客文章 正文
前言
需要使用 macros,则 dart 版本需要 3.5.0以上【Flutter SDK:3.23.0-0.1.pre以上】
使用前vscode配置
1、analysis_options.yaml文件中配置:
analyzer:
enable-experiment:
- macros
2、launch.json文件中配置:
"args": ["--enable-experiment=macros"],
添加库:json
json: ^0.20.2
使用
import 'package:json/json.dart';
@JsonCodable() // 添加此注解
class UserModel {
final String? name;
final String? userName;
final int? age;
final List<WorksModel>? works;
UserModel({
this.name,
this.userName,
this.age,
this.works = const [],
});
}
@JsonCodable()
class WorksModel {
final String? workName;
final String? workDesc;
final String? workProperty;
WorksModel({
this.workName,
this.workDesc,
this.workProperty,
});
}
// json
final userJson = {
'name': 'Marco',
'userName': 'marco4527',
'age': 20,
'works': [
{
'workName': 'Flutter',
'workDesc': 'Flutter is a UI toolkit for building beautiful, natively',
'workProperty': 'URL_Flutter',
},
{
'workName': 'Dart',
'workDesc': 'Dart is a client-optimized language for fast apps on any platform',
'workProperty': 'URL_Dart',
},
],
};
// 转模型
final user = UserModel.fromJson(userJson);
print(user.age);
print(user.name);
print(user.userName);
print(user.toJson());
print(user.works);
猜你喜欢
- 2024-12-23 Python 安装、Vscode IDE配置python开发环境
- 2024-12-23 Asp.net Core启动流程讲解(一)
- 2024-12-23 牛逼!竟然把VSCode玩成了IDEA的效果,有点哇塞
- 2024-12-23 WebCAD快速入门(在线CAD如何快速搭建和入门)网页浏览和编辑dwg
- 2024-12-23 VS Code 编译和调试C/C++程序也可以这么爽
- 2024-12-23 vscode使用vs2022 msvc编译器
- 2024-12-23 分布式/微服务必配APM系统,SkyWalking让你不迷路
- 2024-12-23 我用VS Code 开发工具来开发 自己的 Flutter 应用 工具快而轻
- 2024-12-23 Flutter 实战经验(五):在 VS Code 里开发 Flutter 应用
- 2024-12-23 人生苦短,不光要用 Python,还要在 VSCode 里用 | 原力计划
你 发表评论:
欢迎- 最近发表
-
- 给3D Slicer添加Python第三方插件库
- Python自动化——pytest常用插件详解
- Pycharm下安装MicroPython Tools插件(ESP32开发板)
- IntelliJ IDEA 2025.1.3 发布(idea 2020)
- IDEA+Continue插件+DeepSeek:开发者效率飙升的「三体组合」!
- Cursor:提升Python开发效率的必备IDE及插件安装指南
- 日本旅行时想借厕所、买香烟怎么办?便利商店里能解决大问题!
- 11天!日本史上最长黄金周来了!旅游万金句总结!
- 北川景子&DAIGO缘定1.11 召开记者会宣布结婚
- PIKO‘PPAP’ 洗脑歌登上美国告示牌
- 标签列表
-
- ifneq (61)
- messagesource (56)
- aspose.pdf破解版 (56)
- promise.race (63)
- 2019cad序列号和密钥激活码 (62)
- window.performance (66)
- qt删除文件夹 (72)
- mysqlcaching_sha2_password (64)
- ubuntu升级gcc (58)
- nacos启动失败 (64)
- ssh-add (70)
- jwt漏洞 (58)
- macos14下载 (58)
- yarnnode (62)
- abstractqueuedsynchronizer (64)
- source~/.bashrc没有那个文件或目录 (65)
- springboot整合activiti工作流 (70)
- jmeter插件下载 (61)
- 抓包分析 (60)
- idea创建mavenweb项目 (65)
- vue回到顶部 (57)
- qcombobox样式表 (68)
- vue数组concat (56)
- tomcatundertow (58)
- pastemac (61)
本文暂时没有评论,来添加一个吧(●'◡'●)