- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
下面是我的模型类:
crm_dependent_list_model.dart(模型类)
import 'crm_dep_entitlement_model.dart';
class DependantModel{
String name;
String relationship;
EntitlementsModel entitlements;
DependantModel({this.name, this.relationship, this.entitlements});
factory DependantModel.fromJson(Map depjson){
return DependantModel(
name: depjson["Name"].toString(),
relationship: depjson["Relationship"].toString(),
entitlements: EntitlementsModel.fromJson(depjson["Entitlements"])
);
}
}
这是位于 DependantModel 类中的 EntitlementsModel
crm_dep_entitlement_model.dart
class EntitlementsModel{
final GP gp;
final OPS ops;
final IP ip;
final Dental dental;
final Optical optical;
final EHS ehs;
EntitlementsModel({this.gp, this.ops, this.ip, this.dental, this.optical, this.ehs});
factory EntitlementsModel.fromJson(Map ejson){
return EntitlementsModel(
gp: GP.fromJson(ejson["GP"]),
ops: OPS.fromJson(ejson["OPS"]),
ip: IP.fromJson(ejson["IP"]),
dental: Dental.fromJson(ejson["Dental"]),
optical: Optical.fromJson(ejson["Optical"]),
ehs: EHS.fromJson(ejson["EHS"])
);
}
}
//GP class
class GP{
final String entitlement, utilisation, balance;
GP({this.entitlement, this.utilisation, this.balance});
factory GP.fromJson(Map gjson){
return GP(
entitlement: gjson["Entitlement"].toString(),
utilisation: gjson["Utilisation"].toString(),
balance: gjson["Balance"].toString()
);
}
}
//OPS class
class OPS{
final String entitlement, utilisation, balance;
OPS({this.entitlement, this.utilisation, this.balance});
factory OPS.fromJson(Map gjson){
return OPS(
entitlement: gjson["Entitlement"].toString(),
utilisation: gjson["Utilisation"].toString(),
balance: gjson["Balance"].toString()
);
}
}
//IP class
class IP{
final String entitlement, utilisation, balance;
IP({this.entitlement, this.utilisation, this.balance});
factory IP.fromJson(Map gjson){
return IP(
entitlement: gjson["Entitlement"].toString(),
utilisation: gjson["Utilisation"].toString(),
balance: gjson["Balance"].toString()
);
}
}
//Dental class
class Dental{
final String entitlement, utilisation, balance;
Dental({this.entitlement, this.utilisation, this.balance});
factory Dental.fromJson(Map gjson){
return Dental(
entitlement: gjson["Entitlement"].toString(),
utilisation: gjson["Utilisation"].toString(),
balance: gjson["Balance"].toString()
);
}
}
//Optical class
class Optical{
final String entitlement, utilisation, balance;
Optical({this.entitlement, this.utilisation, this.balance});
factory Optical.fromJson(Map gjson){
return Optical(
entitlement: gjson["Entitlement"].toString(),
utilisation: gjson["Utilisation"].toString(),
balance: gjson["Balance"].toString()
);
}
}
//EHS class
class EHS{
final String entitlement, utilisation, balance;
EHS({this.entitlement, this.utilisation, this.balance});
factory EHS.fromJson(Map gjson){
return EHS(
entitlement: gjson["Entitlement"].toString(),
utilisation: gjson["Utilisation"].toString(),
balance: gjson["Balance"].toString()
);
}
}
该模型类当前用于从该类中的 JSON 中提取数据:
Fifth.dart(调用JSON数据的类)
import 'package:flutter/material.dart';
import 'package:emas_app/Dependant.dart' as Dep;
import 'model/crm_dependent_list_model.dart';
import 'dart:convert';
import 'dart:async';
import 'package:http/http.dart' as http;
final String url = "http://crm.emastpa.com.my/MemberInfo.json";
//Future to get list of dependent names
Future<List<DependantModel>> fetchUserInfo() async{
http.Response response = await http.get(url);
var responsejson = json.decode(response.body);
return(responsejson[0]['Dependents'] as List)
.map((user) => DependantModel.fromJson(user))
.toList();
}
class Fifth extends StatefulWidget {
@override
_FifthState createState() => _FifthState();
}
class _FifthState extends State<Fifth> {
static Future<List<DependantModel>> depState;
@override
void initState() {
depState = fetchUserInfo();
super.initState();
}
@override
Widget build(BuildContext context) {
//ListView.builder inside FutureBuilder
var futureBuilder = new FutureBuilder(
future: depState,
builder: (context, snapshot){
switch(snapshot.connectionState){
case ConnectionState.none:
case ConnectionState.waiting:
return new Center(
child: new CircularProgressIndicator(),
);
default:
if(snapshot.hasError){
return new Text(snapshot.error);
}else{
List<DependantModel> user = snapshot.data;
return new ListView.builder(
itemCount: user.length,
itemBuilder: (context, index){
return new Column(
children: <Widget>[
new ListTile(
title: new Text(user[index].name,
style: TextStyle(fontSize: 20.0)),
subtitle: new Text(user[index].relationship,
style: TextStyle(fontSize: 15.0)),
trailing: new MaterialButton(color: Colors.greenAccent,
textColor: Colors.white,
child: new Text("More"),
onPressed: (){
Navigator.push(context,
new MaterialPageRoute(builder: (context) => Dep.Dependents(name: user[index].name, entitlementsModel: user[index].entitlements))
);
}
),
)
],
);
});
}
}
});
return new Scaffold(
body: futureBuilder,
);
}
}
Fifth.dart 类将通过此类中的构造函数发送数据:
Dependent.dart(带有构造函数的类)
import 'model/crm_dep_entitlement_model.dart';
import 'package:flutter/material.dart';
import 'dart:convert';
import 'dart:async';
import 'package:http/http.dart' as http;
import 'model/crm_dependent_list_model.dart';
import 'package:flutter/foundation.dart';
final String url = "http://crm.emastpa.com.my/MemberInfo.json";
//Future method to fetch information
Future<EntitlementsModel> fetchEntitlements() async{
final response = await http.get(url);
final jsonresponse = json.decode(response.body);
var res = jsonresponse[0]["Dependents"][0]["Entitlements"];
return EntitlementsModel.fromJson(jsonresponse[0]["Dependents"][0]["Entitlements"]);
}
//void main() => runApp(Dependents());
class Dependents extends StatefulWidget {
final String name;
// final Map entitlement;
final EntitlementsModel entitlementsModel;
//Constructor to accept the value from Fifth.dart
// Dependents({Key key, this.name, this.dependantModel) : super(key: key);
Dependents({Key key, this.name, this.entitlementsModel}) : super(key:key);
@override
_DependentsState createState() => _DependentsState();
}
class _DependentsState extends State<Dependents> {
Future<EntitlementsModel> entitlement;
@override
void initState() {
entitlement = fetchEntitlements();
super.initState();
}
@override
Widget build(BuildContext context) {
//new body widget
Widget body = new Container(
child: new Center(
child: new FutureBuilder(
future: entitlement,
builder: (context, snapshot){
if(snapshot.hasData){
var entitledata = snapshot.data;
//retrieve data from snapshot
var gpentitlement = entitledata.gp.entitlement;
var gputilisation = entitledata.gp.utilisation;
var gpbalance = entitledata.gp.balance;
var opsentitle = entitledata.ip.entitlement;
var opsutilisation = entitledata.ip.utilisation;
var opsbalance = entitledata.ip.balance;
return new Column(
children: <Widget>[
new ListTile(
title: new Text("Name: "),
subtitle: new Text("${widget.name}"),
) ,
new Divider(
color: Colors.black,
),
new ListTile(
title: new Text("Clinic GP",
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
) ,
new ListTile(
title: new Text("Entitlement"),
trailing: new Text(gpentitlement),
),
new ListTile(
title: new Text("Utilisation"),
trailing: new Text(gputilisation),
),
new ListTile(
title: new Text("Balance"),
trailing: new Text(gpbalance),
),
new Divider(
color: Colors.black,
),
new ListTile(
title: new Text("IP",
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
),
new ListTile(
title: new Text("Entitlement"),
trailing: new Text(opsentitle),
),
new ListTile(
title: new Text("Utilisation"),
trailing: new Text(opsutilisation),
),
new ListTile(
title: new Text("Balance"),
trailing: new Text(opsbalance),
),
],
);
}else if(snapshot.hasError){
return new Text(snapshot.error);
}
//loading the page
return new Center(
child: new CircularProgressIndicator(),
);
}),
),
);
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('${widget.name}'),
),
body: body
),
);
}
}
这是我遇到的错误:
compiler message: lib/Fifth.dart:72:155: Error: The argument type '#lib1::EntitlementsModel' can't be assigned to the parameter type '#lib2::EntitlementsModel'.
compiler message: Try changing the type of the parameter, or casting the argument to '#lib2::EntitlementsModel'.
compiler message: new MaterialPageRoute(builder: (context) => Dep.Dependents(name: user[index].name, entitlementsModel: user[index].entitlements))
compiler message:
还有:
I/flutter ( 6816): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter ( 6816): The following assertion was thrown building FutureBuilder<List<DependantModel>>(dirty, state:
I/flutter ( 6816): _FutureBuilderState<List<DependantModel>>#bdb2c):
I/flutter ( 6816): type 'NoSuchMethodError' is not a subtype of type 'String'
我的问题是:
我该如何解决这个错误,因为它说我应该转换参数,但我不知道如何解决,因为 EntitlementsModel 是一个包含多个 map 类的类。
最佳答案
EntitlementsModel
的导入似乎存在冲突。尝试将所有导入重写为以下形式:
import 'package:YOUR_PACKAGE/../...dart'
'YOUR_PACKAGE' 应该是应用程序的名称,如 pubspec.yml name
变量中所述。
目录结构包括从 lib
文件夹(不包括它)到导入的 dart 文件的所有文件夹。
(您在 Fifth.dart 文件的第二行使用此导入方案)
关于json - 参数类型 'x' 无法分配给参数类型 'x',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51944139/
最近开始学习MongoDB。今天老师教了我们 mongoexport 命令。在练习时,我遇到了一个典型的问题,包括教练在内的其他同学都没有遇到过。我在我的 Windows 10 机器上使用 Mongo
我是 JSON Schema 的新手,读过什么是 JSON Schema 等等。但我不知道如何将 JSON Schema 链接到 JSON 以针对该 JSON Schema 进行验证。谁能解释一下?
在 xml 中,我可以在另一个 xml 文件中包含一个文件并使用它。如果您的软件从 xml 获取配置文件但没有任何方法来分离配置,如 apache/ngnix(nginx.conf - site-av
我有一个 JSON 对象,其中包含一个本身是 JSON 对象的字符串。我如何反序列化它? 我希望能够做类似的事情: #[derive(Deserialize)] struct B { c: S
考虑以下 JSON { "a": "{\"b\": 12, \"c\": \"test\"}" } 我想定义一个泛型读取 Reads[Outer[T]]对于这种序列化的 Json import
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 11 个月前关闭。 Improve
我的旧项目在 MySQL 中有 Standard JSON 格式的数据。 对于我在 JS (Node.js) 和 DynamoDB 中的全新项目,关于 Standard JSON格式: 是否建议将其转
JSON 值字符串、数字、true、false、null 是否是有效的 JSON? 即,是 true 一个有效的 JSON 文档?还是必须是数组/对象? 一些验证器接受这个(例如 http://jso
我有一个 JSON 字符串,其中一个字段是文本字段。这个文本字段可以包含用户在 UI 中输入的文本,如果他们输入的文本是 JSON 文本,也许是为了说明一些编码,我需要对他们的文本进行编码,以便它不会
我正在通过 IBM MQ 调用处理数据,当由 ColdFusion 10 (10,0,11,285437) 序列化时,0 将作为 +0.0 返回,它会导致无效的 JSON并且无法反序列化。 stPol
我正在从三个数组中生成一个散列,然后尝试构建一个 json。我通过 json object has array 成功了。 require 'json' A = [['A1', 'A2', 'A3'],
我从 API 接收 JSON,响应可以是 30 种类型之一。每种类型都有一组唯一的字段,但所有响应都有一个字段 type 说明它是哪种类型。 我的方法是使用serde .我为每种响应类型创建一个结构并
我正在下载一个 JSON 文件,我已将其检查为带有“https://jsonlint.com”的有效 JSON 到文档目录。然后我打开文件并再次检查,结果显示为无效的 JSON。这怎么可能????这是
我正在尝试根据从 API 接收到的数据动态创建一个 JSON 对象。 收到的示例数据:将数据解码到下面给出的 CiItems 结构中 { "class_name": "test", "
我想从字符串转换为对象。 来自 {"key1": "{\n \"key2\": \"value2\",\n \"key3\": {\n \"key4\": \"value4\"\n }\n
目前我正在使用以下代码将嵌套的 json 转换为扁平化的 json: import ( "fmt" "github.com/nytlabs/gojsonexplode" ) func
我有一个使用来自第三方 API 的数据的应用程序。我需要将 json 解码为一个结构,这需要该结构具有“传入”json 字段的 json 标签。传出的 json 字段具有不同的命名约定,因此我需要不同
我想使用 JSON 架构来验证某些值。我有两个对象,称它们为 trackedItems 和 trackedItemGroups。 trackedItemGroups 是组名称和 trackedItem
考虑以下案例类模式, case class Y (a: String, b: String) case class X (dummy: String, b: Y) 字段b是可选的,我的一些数据集没有字
我正在存储 cat ~/path/to/file/blah | 的输出jq tojson 在一个变量中,稍后在带有 JSON 内容的 curl POST 中使用。它运作良好,但它删除了所有换行符。我知
我是一名优秀的程序员,十分优秀!