网站首页 > 博客文章 正文
前言
需要使用 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 里用 | 原力计划
你 发表评论:
欢迎- 367℃用AI Agent治理微服务的复杂性问题|QCon
- 359℃手把手教程「JavaWeb」优雅的SpringMvc+Mybatis整合之路
- 358℃初次使用IntelliJ IDEA新建Maven项目
- 351℃Maven技术方案最全手册(mavena)
- 348℃安利Touch Bar 专属应用,让闲置的Touch Bar活跃起来!
- 346℃InfoQ 2024 年趋势报告:架构篇(infoq+2024+年趋势报告:架构篇分析)
- 345℃IntelliJ IDEA 2018版本和2022版本创建 Maven 项目对比
- 342℃从头搭建 IntelliJ IDEA 环境(intellij idea建包)
- 最近发表
- 标签列表
-
- powershellfor (55)
- 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)
本文暂时没有评论,来添加一个吧(●'◡'●)