flutter - Flutter 从小部件生成 JSON
问题描述
我想让我的应用程序动态化。有没有办法可以在任何颤振应用程序中从我的小部件生成 JSON?
我找到了仅用于从 JSON 解析到小部件的解决方案,但我需要相反的方式。
解决方案
老实说,我不确定这是否是最好的方法......但我认为你可以使用类似下面的东西来手动生成 JSON ......
myPrint(dynamic widget){
if(widget is Column || widget is Row || widget is Stack){
for(dynamic w in widget.children){
print(widget.toString());
myPrint(w);
}
}else{
print(widget.toString());
try {
myPrint(widget.child);
} catch (e) {
}
}
}
例如下面的小部件...
var myWidget = Column(
children: [
Center(
child: Text("word" , style: TextStyle(fontSize: 25),),
),
],
);
像这样打印...
Column(direction: vertical, mainAxisAlignment: start, crossAxisAlignment: center)
Center(alignment: center)
Text("word", inherit: true, size: 25.0)
推荐阅读
- django - Django Installed Apps - path full/partial
- ruby-on-rails-5 - Dynamic page caching failing in Rails 5
- python - 查找图像上的特定点
- java - Jackson FAIL_ON_UNKNOWN_PROPERTIES 为 false 不起作用
- php - “.default”在 Symfony 服务 ID 中有什么特殊意义吗?
- powerbi - Power BI 比较日期
- c# - 是否可以从 C# 中的根 CA 动态生成 SSL 证书?
- jquery - 无法访问 DataTables 实例
- python - 如何按照 list(aList) 的原始出现顺序获取 list(set(aList)) 值?
- javascript - 禁用 Chrome 网络安全后仍然强制执行 CORS?