Print语句或其下面的任何内容均未运行,并且错误消息指出了问题所在,即以var time开头的最后一行.我还验证了地震是一个可增长的列表,这意味着地震[0]应该没有问题,但事实并非如此……我在做什么错?让我知道这个问题是否需要进一步说明,我会提供.
链接到错误gif
链接到GitHub上的code
我的代码中有问题的部分如下.在第43行报告错误.
import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:intl/intl.dart';
class Quake extends StatefulWidget {
var _data;
Quake(this._data);
@override
State<StatefulWidget> createState() => new QuakeState(_data);
}
class QuakeState extends State<Quake> {
// https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson
// "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson";
var _data;
QuakeState(this._data);
@override
Widget build(BuildContext context) {
// debugPrint(_data['features'].runtimeType.toString());
List earthquakes = _data['features'];
return new Scaffold(
appBar: new AppBar(
title: new Text("Quakes - USGS All Earthquakes"),
backgroundColor: Colors.red,
centerTitle: true,
),
body: new ListView.builder(
itemCount: earthquakes.length,
itemBuilder: (BuildContext context, int index) {
print("${earthquakes[index]}");
var earthquake = earthquakes[index];
var time = earthquake['properties']['time'];
time *= 1000;
//var dateTime = new DateTime.fromMillisecondsSinceEpoch(int.parse(time));
//time = new DateFormat.yMMMMd(dateTime).add_jm();
return new ListTile(
title: new Text(time ?? "Empty"),
);
}));
}
}
Future<Map> getJson(String url) async {
return await http.get(url).then((response) => json.decode(response.body));
}
解决方法:
title: new Text(time ?? "Empty"),
应该
title: new Text(time != null ? '$time' : "Empty"),
要么
title: new Text('${time ?? "Empty"}'),
原文地址:https://codeday.me/bug/20191025/1926440.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。