在flatter/Dart中解析JSON:<;RK、RV>;()=>;地图<;RK,RV>,NoSuchMethodError-(数组问题?)
我对flatter/Dart还是有点陌生,我在解析JSON方面已经挣扎了很长一段时间。这对我来说似乎是一项艰巨的任务,尽管我认为我的JSON结构并没有那么复杂 非常感谢你的帮助 这是我要解析的JSON:在flatter/Dart中解析JSON:<;RK、RV>;()=>;地图<;RK,RV>,NoSuchMethodError-(数组问题?),json,parsing,flutter,dart,Json,Parsing,Flutter,Dart,我对flatter/Dart还是有点陌生,我在解析JSON方面已经挣扎了很长一段时间。这对我来说似乎是一项艰巨的任务,尽管我认为我的JSON结构并没有那么复杂 非常感谢你的帮助 这是我要解析的JSON: { "predictionICL":{ "openingTimeToday":"8:00 - 23:00", "openingTimeTomorrow":"8:00 - 23:00", "percentagesToday":[ 3,
{
"predictionICL":{
"openingTimeToday":"8:00 - 23:00",
"openingTimeTomorrow":"8:00 - 23:00",
"percentagesToday":[
3,
5,
11,
17,
20,
23,
25,
26,
25,
29,
30,
32,
31,
35,
40,
43,
44,
46,
49,
53,
50,
56,
54,
60,
62,
61,
69,
70,
75,
76,
84,
90,
94,
100,
93,
81,
72,
70,
73,
71,
63,
59,
55,
56,
51,
49,
50,
45,
43,
40,
38,
35,
31,
27,
25,
23,
20,
20,
19,
17,
12,
9,
8,
2,
1
],
"percentagesTomorrow":[
0,
0,
1,
7,
14,
20,
22,
21,
21,
22,
20,
25,
27,
31,
30,
31,
32,
33,
30,
34,
35,
33,
35,
37,
39,
40,
40,
39,
38,
40,
41,
38,
34,
37,
34,
35,
33,
32,
31,
30,
33,
30,
31,
30,
29,
30,
27,
28,
26,
23,
20,
19,
16,
17,
15,
12,
10,
7,
5,
1,
1,
0,
0,
0,
0
]
},
"predictionRandwyck":{
"openingTimeToday":"8:00 - 23:00",
"openingTimeTomorrow":"8:00 - 23:00",
"percentagesToday":[
3,
5,
11,
17,
20,
23,
25,
26,
25,
29,
30,
32,
31,
35,
40,
43,
44,
46,
49,
53,
50,
56,
54,
60,
62,
61,
69,
70,
75,
76,
84,
90,
94,
100,
93,
81,
72,
70,
73,
71,
63,
59,
55,
56,
51,
49,
50,
45,
43,
40,
38,
35,
31,
27,
25,
23,
20,
20,
19,
17,
12,
9,
8,
2,
1
],
"percentagesTomorrow":[
0,
0,
1,
7,
14,
20,
22,
21,
21,
22,
20,
25,
27,
31,
30,
31,
32,
33,
30,
34,
35,
33,
35,
37,
39,
40,
40,
39,
38,
40,
41,
38,
34,
37,
34,
35,
33,
32,
31,
30,
33,
30,
31,
30,
29,
30,
27,
28,
26,
23,
20,
19,
16,
17,
15,
12,
10,
7,
5,
1,
1,
0,
0,
0,
0
]
},
"predictionTapijn":{
"openingTimeToday":"8:00 - 23:00",
"openingTimeTomorrow":"8:00 - 23:00",
"percentagesToday":[
3,
5,
11,
17,
20,
23,
25,
26,
25,
29,
30,
32,
31,
35,
40,
43,
44,
46,
49,
53,
50,
56,
54,
60,
62,
61,
69,
70,
75,
76,
84,
90,
94,
100,
93,
81,
72,
70,
73,
71,
63,
59,
55,
56,
51,
49,
50,
45,
43,
40,
38,
35,
31,
27,
25,
23,
20,
20,
19,
17,
12,
9,
8,
2,
1
],
"percentagesTomorrow":[
0,
0,
1,
7,
14,
20,
22,
21,
21,
22,
20,
25,
27,
31,
30,
31,
32,
33,
30,
34,
35,
33,
35,
37,
39,
40,
40,
39,
38,
40,
41,
38,
34,
37,
34,
35,
33,
32,
31,
30,
33,
30,
31,
30,
29,
30,
27,
28,
26,
23,
20,
19,
16,
17,
15,
12,
10,
7,
5,
1,
1,
0,
0,
0,
0
]
},
"message":"optionalmessageString"
}
它基本上只有三个datatype LibraryPrediction实例和一个可选的消息字符串
数据类型库预测由一个字符串“openingTimeToday”、一个字符串“openingTimeTomorrow”和两个双数组“percentagesToday”和“percentagesTomorrow”组成
现在,我正试图从上面的磁盘解析json,因为我的服务器还没有运行。
这是我目前的代码:
我有一个服务文件:
import 'dart:convert';
import 'package:flutter/services.dart';
import 'package:test_app/models/predictions_update_model.dart';
PredictionsUpdate parseUpdate(String responseBody) {
final jsonResponse = json.decode(responseBody).cast<Map<String, dynamic>>();
PredictionsUpdate update = jsonResponse.map<PredictionsUpdate>((json) => PredictionsUpdate.fromJson(json));
return update;
}
Future<PredictionsUpdate> fetchUpdate() async {
final response = await rootBundle.loadString('lib/testJson/data.json');
return parseUpdate(response);
}
导入'dart:convert';
导入“包:flifter/services.dart”;
导入“package:test_app/models/predictions_update_model.dart”;
PredictionsUpdate解析更新(字符串响应库){
final jsonResponse=json.decode(responseBody.cast();
PredictionsUpdate=jsonResponse.map((json)=>PredictionsUpdate.fromJson(json));
返回更新;
}
Future fetchUpdate()异步{
最终响应=等待rootBundle.loadString('lib/testJson/data.json');
返回更新(响应);
}
和一个模型文件:
class PredictionsUpdate {
final LibraryPrediction predictionICL;
final LibraryPrediction predictionRandwyck;
final LibraryPrediction predictionTapijn;
final String message;
PredictionsUpdate({
this.predictionICL,
this.predictionRandwyck,
this.predictionTapijn,
this.message,
});
factory PredictionsUpdate.fromJson(Map<String, dynamic> parsedJson){
return PredictionsUpdate(
predictionICL: LibraryPrediction.fromJson(parsedJson['predictionICL']),
predictionRandwyck: LibraryPrediction.fromJson(parsedJson['predictionRandwyck']),
predictionTapijn: LibraryPrediction.fromJson(parsedJson['predictionTapijn']),
message: parsedJson['message'] as String,
);
}
}
class LibraryPrediction {
final String openingTimeToday;
final String openingTimeTomorrow;
final List<double> percentagesToday;
final List<double> percentagesTomorrow;
LibraryPrediction({
this.openingTimeToday,
this.openingTimeTomorrow,
this.percentagesToday,
this.percentagesTomorrow,
});
factory LibraryPrediction.fromJson(Map<String, dynamic> json){
return LibraryPrediction(
openingTimeToday: json['openingTimeToday'] as String,
openingTimeTomorrow: json['openingTimeTomorrow'] as String,
percentagesToday: json['percentagesToday'] as List<double>,
percentagesTomorrow: json['percentagesTomorrow'] as List<double>,
);
}
}
类预测更新{
最终图书馆预测;
最终图书馆预测Randwyck;
最终图书馆预测Tapijn;
最终字符串消息;
预测更新({
这个预测,
这个,预测兰德威克,
这个,预测塔皮恩,
这条信息,
});
factory PredictionsUpdate.fromJson(Map parsedJson){
返回预测更新(
predictionICL:LibraryPrediction.fromJson(parsedJson['predictionICL']),
predictionRandwyck:LibraryPrediction.fromJson(parsedJson['predictionRandwyck']),
predictionTapijn:LibraryPrediction.fromJson(parsedJson['predictionTapijn']),
message:parsedJson['message']作为字符串,
);
}
}
类库预测{
最终管柱打开时间为今天;
最终字符串打开时间为明天;
每天的最终列表百分比;
明天的最终列表百分比;
图书馆预测({
这是今天的开幕式,
这是明天的开幕式,
今天是百分之三十,
今天,明天,
});
factory LibraryPrediction.fromJson(映射json){
回归预测(
openingTimeToday:json['openingTimeToday']作为字符串,
openingTimeTomorrow:json['openingTimeTomorrow']作为字符串,
percentagesToday:json['percentagesToday']作为列表,
percentagesTomorrow:json['percentagesTomorrow']作为列表,
);
}
}
这就是我调用函数的方式:
Row(
children: <Widget>[
RaisedButton(
child: Text('update'),
onPressed: () {
Future<PredictionsUpdate> futureUpdate = fetchUpdate();
futureUpdate.then((update)=> widget.currentNumbers = update)
.catchError((error) => print(error));
},
),
],
),
划船(
儿童:[
升起的按钮(
子项:文本('update'),
已按下:(){
Future futureUpdate=fetchUpdate();
futureUpdate.then((更新)=>widget.currentNumbers=update)
.catchError((错误)=>打印(错误));
},
),
],
),
每当我尝试解析JSON时,都会出现以下错误:
flutter: NoSuchMethodError: Class '_InternalLinkedHashMap<String, dynamic>' has no instance method 'cast' with matching arguments.
Receiver: _LinkedHashMap len:4
Tried calling: cast<Map<String, dynamic>>()
Found: cast<RK, RV>() => Map<RK, RV>
flatter:NoSuchMethodError:类“\u InternalLinkedHashMap”没有具有匹配参数的实例方法“cast”。
接收器:_LinkedHashMapLen:4
已尝试呼叫:cast()
找到:cast()=>映射
我有这样一种感觉,当我试图解析双数组“percentagesToday”或“percentagesTomorrow”时,错误就起源于某个地方,但我不能确定,我也无法从错误消息中获得更多线索
如果您能帮助我找出错误所在,我将不胜感激。您可以复制下面的粘贴运行完整代码
您可以这样做
List.from(json[“percentagesToday”].map((x)=>x.toDouble()),
代码片段
factory LibraryPrediction.fromJson(Map<String, dynamic> json) =>
LibraryPrediction(
openingTimeToday: json["openingTimeToday"],
openingTimeTomorrow: json["openingTimeTomorrow"],
percentagesToday: List<double>.from(
json["percentagesToday"].map((x) => x.toDouble())),
percentagesTomorrow: List<double>.from(
json["percentagesTomorrow"].map((x) => x.toDouble())),
);
...
futureUpdate.then((update) {
print('${update.predictionIcl.openingTimeToday.toString()}');
print('${update.message}');
print('${update.predictionRandwyck.openingTimeTomorrow}');
}).catchError((error) => print(error));
完整代码
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
PredictionsUpdate predictionsUpdateFromJson(String str) =>
PredictionsUpdate.fromJson(json.decode(str));
class PredictionsUpdate {
LibraryPrediction predictionIcl;
LibraryPrediction predictionRandwyck;
LibraryPrediction predictionTapijn;
String message;
PredictionsUpdate({
this.predictionIcl,
this.predictionRandwyck,
this.predictionTapijn,
this.message,
});
factory PredictionsUpdate.fromJson(Map<String, dynamic> json) =>
PredictionsUpdate(
predictionIcl: LibraryPrediction.fromJson(json["predictionICL"]),
predictionRandwyck:
LibraryPrediction.fromJson(json["predictionRandwyck"]),
predictionTapijn: LibraryPrediction.fromJson(json["predictionTapijn"]),
message: json["message"],
);
}
class LibraryPrediction {
String openingTimeToday;
String openingTimeTomorrow;
List<double> percentagesToday;
List<double> percentagesTomorrow;
LibraryPrediction({
this.openingTimeToday,
this.openingTimeTomorrow,
this.percentagesToday,
this.percentagesTomorrow,
});
factory LibraryPrediction.fromJson(Map<String, dynamic> json) =>
LibraryPrediction(
openingTimeToday: json["openingTimeToday"],
openingTimeTomorrow: json["openingTimeTomorrow"],
percentagesToday: List<double>.from(
json["percentagesToday"].map((x) => x.toDouble())),
percentagesTomorrow: List<double>.from(
json["percentagesTomorrow"].map((x) => x.toDouble())),
);
}
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
Future<PredictionsUpdate> fetchUpdate() async {
String jsonString = '''
{
"predictionICL":{
"openingTimeToday":"8:00 - 23:00",
"openingTimeTomorrow":"8:00 - 23:00",
"percentagesToday":[
3,
5,
11,
17,
20,
23,
25,
26,
25,
29,
30,
32,
31,
35,
40,
43,
44,
46,
49,
53,
50,
56,
54,
60,
62,
61,
69,
70,
75,
76,
84,
90,
94,
100,
93,
81,
72,
70,
73,
71,
63,
59,
55,
56,
51,
49,
50,
45,
43,
40,
38,
35,
31,
27,
25,
23,
20,
20,
19,
17,
12,
9,
8,
2,
1
],
"percentagesTomorrow":[
0,
0,
1,
7,
14,
20,
22,
21,
21,
22,
20,
25,
27,
31,
30,
31,
32,
33,
30,
34,
35,
33,
35,
37,
39,
40,
40,
39,
38,
40,
41,
38,
34,
37,
34,
35,
33,
32,
31,
30,
33,
30,
31,
30,
29,
30,
27,
28,
26,
23,
20,
19,
16,
17,
15,
12,
10,
7,
5,
1,
1,
0,
0,
0,
0
]
},
"predictionRandwyck":{
"openingTimeToday":"8:00 - 23:00",
"openingTimeTomorrow":"8:00 - 23:00",
"percentagesToday":[
3,
5,
11,
17,
20,
23,
25,
26,
25,
29,
30,
32,
31,
35,
40,
43,
44,
46,
49,
53,
50,
56,
54,
60,
62,
61,
69,
70,
75,
76,
84,
90,
94,
100,
93,
81,
72,
70,
73,
71,
63,
59,
55,
56,
51,
49,
50,
45,
43,
40,
38,
35,
31,
27,
25,
23,
20,
20,
19,
17,
12,
9,
8,
2,
1
],
"percentagesTomorrow":[
0,
0,
1,
7,
14,
20,
22,
21,
21,
22,
20,
25,
27,
31,
30,
31,
32,
33,
30,
34,
35,
33,
35,
37,
39,
40,
40,
39,
38,
40,
41,
38,
34,
37,
34,
35,
33,
32,
31,
30,
33,
30,
31,
30,
29,
30,
27,
28,
26,
23,
20,
19,
16,
17,
15,
12,
10,
7,
5,
1,
1,
0,
0,
0,
0
]
},
"predictionTapijn":{
"openingTimeToday":"8:00 - 23:00",
"openingTimeTomorrow":"8:00 - 23:00",
"percentagesToday":[
3,
5,
11,
17,
20,
23,
25,
26,
25,
29,
30,
32,
31,
35,
40,
43,
44,
46,
49,
53,
50,
56,
54,
60,
62,
61,
69,
70,
75,
76,
84,
90,
94,
100,
93,
81,
72,
70,
73,
71,
63,
59,
55,
56,
51,
49,
50,
45,
43,
40,
38,
35,
31,
27,
25,
23,
20,
20,
19,
17,
12,
9,
8,
2,
1
],
"percentagesTomorrow":[
0,
0,
1,
7,
14,
20,
22,
21,
21,
22,
20,
25,
27,
31,
30,
31,
32,
33,
30,
34,
35,
33,
35,
37,
39,
40,
40,
39,
38,
40,
41,
38,
34,
37,
34,
35,
33,
32,
31,
30,
33,
30,
31,
30,
29,
30,
27,
28,
26,
23,
20,
19,
16,
17,
15,
12,
10,
7,
5,
1,
1,
0,
0,
0,
0
]
},
"message":"optionalmessageString"
}
''';
//final response = await rootBundle.loadString('lib/testJson/data.json');
final http.Response response = http.Response(jsonString, 200);
PredictionsUpdate payload = predictionsUpdateFromJson(response.body);
return payload;
}
void _incrementCounter() {
Future<PredictionsUpdate> futureUpdate = fetchUpdate();
futureUpdate.then((update) {
print('${update.predictionIcl.openingTimeToday.toString()}');
print('${update.message}');
print('${update.predictionRandwyck.openingTimeTomorrow}');
}).catchError((error) => print(error));
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
导入“包装:颤振/材料.省道”;
将“package:http/http.dart”导入为http;
导入“dart:convert”;
PredictionsUpdate predictionsUpdateFromJson(字符串str)=>
PredictionsUpdate.fromJson(json.decode(str));
类预测更新{
图书馆预测;
图书馆预测;兰德威克;
图书馆预测;
字符串消息;
预测更新({
这个预测,
这个,预测兰德威克,
这个,预测塔皮恩,
这条信息,
});
factory PredictionsUpdate.fromJson(映射json)=>
预测更新(
predictionIcl:LibraryPrediction.fromJson(json[“predictionIcl”]),
预测兰德威克:
LibraryPrediction.fromJson(json[“predictionRandwyck”]),
predictionTapijn:LibraryPrediction.fromJson(json[“predictionTapijn”]),
message:json[“message”],
);
}
类库预测{
字符串打开时间;
明天打开字符串;
每天列出百分比;
列出明天的百分比;
图书馆预测({
这是今天的开幕式,
这是明天的开幕式,
今天是百分之三十,
今天,明天,
});
factory LibraryPrediction.fromJson(映射json)=>
图书馆预测(
openingTimeToday:json[“openingTimeToday”],
openingTimeTomorrow:json[“openingTimeTomorrow”],
百分比截止日期:List.from(
json[“percentagesToday”].map((x)=>x.toDouble()),
percentagesTomorrow:List.from(
json[“percentagesTomorrow”].map((x)=>x.toDouble()),
);
}
void main(){
runApp(MyApp());
}
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“颤振演示”,
主题:主题数据(
主样本:颜色。蓝色,
),
主页:MyHomePage(标题:“颤振演示主页”),
);
}
}
类MyHomePage扩展StatefulWidget{
MyHomePage({Key,this.title}):超级(Key:Key);
最后的字符串标题;
@凌驾
_MyHomePageState创建
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
PredictionsUpdate predictionsUpdateFromJson(String str) =>
PredictionsUpdate.fromJson(json.decode(str));
class PredictionsUpdate {
LibraryPrediction predictionIcl;
LibraryPrediction predictionRandwyck;
LibraryPrediction predictionTapijn;
String message;
PredictionsUpdate({
this.predictionIcl,
this.predictionRandwyck,
this.predictionTapijn,
this.message,
});
factory PredictionsUpdate.fromJson(Map<String, dynamic> json) =>
PredictionsUpdate(
predictionIcl: LibraryPrediction.fromJson(json["predictionICL"]),
predictionRandwyck:
LibraryPrediction.fromJson(json["predictionRandwyck"]),
predictionTapijn: LibraryPrediction.fromJson(json["predictionTapijn"]),
message: json["message"],
);
}
class LibraryPrediction {
String openingTimeToday;
String openingTimeTomorrow;
List<double> percentagesToday;
List<double> percentagesTomorrow;
LibraryPrediction({
this.openingTimeToday,
this.openingTimeTomorrow,
this.percentagesToday,
this.percentagesTomorrow,
});
factory LibraryPrediction.fromJson(Map<String, dynamic> json) =>
LibraryPrediction(
openingTimeToday: json["openingTimeToday"],
openingTimeTomorrow: json["openingTimeTomorrow"],
percentagesToday: List<double>.from(
json["percentagesToday"].map((x) => x.toDouble())),
percentagesTomorrow: List<double>.from(
json["percentagesTomorrow"].map((x) => x.toDouble())),
);
}
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
Future<PredictionsUpdate> fetchUpdate() async {
String jsonString = '''
{
"predictionICL":{
"openingTimeToday":"8:00 - 23:00",
"openingTimeTomorrow":"8:00 - 23:00",
"percentagesToday":[
3,
5,
11,
17,
20,
23,
25,
26,
25,
29,
30,
32,
31,
35,
40,
43,
44,
46,
49,
53,
50,
56,
54,
60,
62,
61,
69,
70,
75,
76,
84,
90,
94,
100,
93,
81,
72,
70,
73,
71,
63,
59,
55,
56,
51,
49,
50,
45,
43,
40,
38,
35,
31,
27,
25,
23,
20,
20,
19,
17,
12,
9,
8,
2,
1
],
"percentagesTomorrow":[
0,
0,
1,
7,
14,
20,
22,
21,
21,
22,
20,
25,
27,
31,
30,
31,
32,
33,
30,
34,
35,
33,
35,
37,
39,
40,
40,
39,
38,
40,
41,
38,
34,
37,
34,
35,
33,
32,
31,
30,
33,
30,
31,
30,
29,
30,
27,
28,
26,
23,
20,
19,
16,
17,
15,
12,
10,
7,
5,
1,
1,
0,
0,
0,
0
]
},
"predictionRandwyck":{
"openingTimeToday":"8:00 - 23:00",
"openingTimeTomorrow":"8:00 - 23:00",
"percentagesToday":[
3,
5,
11,
17,
20,
23,
25,
26,
25,
29,
30,
32,
31,
35,
40,
43,
44,
46,
49,
53,
50,
56,
54,
60,
62,
61,
69,
70,
75,
76,
84,
90,
94,
100,
93,
81,
72,
70,
73,
71,
63,
59,
55,
56,
51,
49,
50,
45,
43,
40,
38,
35,
31,
27,
25,
23,
20,
20,
19,
17,
12,
9,
8,
2,
1
],
"percentagesTomorrow":[
0,
0,
1,
7,
14,
20,
22,
21,
21,
22,
20,
25,
27,
31,
30,
31,
32,
33,
30,
34,
35,
33,
35,
37,
39,
40,
40,
39,
38,
40,
41,
38,
34,
37,
34,
35,
33,
32,
31,
30,
33,
30,
31,
30,
29,
30,
27,
28,
26,
23,
20,
19,
16,
17,
15,
12,
10,
7,
5,
1,
1,
0,
0,
0,
0
]
},
"predictionTapijn":{
"openingTimeToday":"8:00 - 23:00",
"openingTimeTomorrow":"8:00 - 23:00",
"percentagesToday":[
3,
5,
11,
17,
20,
23,
25,
26,
25,
29,
30,
32,
31,
35,
40,
43,
44,
46,
49,
53,
50,
56,
54,
60,
62,
61,
69,
70,
75,
76,
84,
90,
94,
100,
93,
81,
72,
70,
73,
71,
63,
59,
55,
56,
51,
49,
50,
45,
43,
40,
38,
35,
31,
27,
25,
23,
20,
20,
19,
17,
12,
9,
8,
2,
1
],
"percentagesTomorrow":[
0,
0,
1,
7,
14,
20,
22,
21,
21,
22,
20,
25,
27,
31,
30,
31,
32,
33,
30,
34,
35,
33,
35,
37,
39,
40,
40,
39,
38,
40,
41,
38,
34,
37,
34,
35,
33,
32,
31,
30,
33,
30,
31,
30,
29,
30,
27,
28,
26,
23,
20,
19,
16,
17,
15,
12,
10,
7,
5,
1,
1,
0,
0,
0,
0
]
},
"message":"optionalmessageString"
}
''';
//final response = await rootBundle.loadString('lib/testJson/data.json');
final http.Response response = http.Response(jsonString, 200);
PredictionsUpdate payload = predictionsUpdateFromJson(response.body);
return payload;
}
void _incrementCounter() {
Future<PredictionsUpdate> futureUpdate = fetchUpdate();
futureUpdate.then((update) {
print('${update.predictionIcl.openingTimeToday.toString()}');
print('${update.message}');
print('${update.predictionRandwyck.openingTimeTomorrow}');
}).catchError((error) => print(error));
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}