print语句和它下面的任何语句都不会运行,错误消息会指向上面以var time开头的最后一行.我还验证了earthquakes是一个可增长的列表,这意味着earthquakes[0]应该运行没有问题,但它不...我做错了什么?如果问题需要进一步澄清,请告诉我,我会提供.

我的代码中有问题的部分如下所示.第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"}'),

Flutter相关问答推荐

Flutter:带有表单的SpeechToTextprovider

flutter:如何将字体大小设置得更大(更大)

在Riverpod ConsumerWidget中使用文本编辑控制器

Android Studio中的Ffltter&;Couchbase:进程C:/Program Files/Git/bin/bash以非零退出值35结束

从超级应用程序启动时,Flutter 小应用程序中未加载资源

无法在我的Flutter 应用程序中使用GoRouter测试导航

如何管理枚举类型的阻塞事件?

无法构建AndroidBundle 包或iOS等

如何从RealmResults获取Flutter Flutter 流?

应为标识符,并应为查找)错误

如何让两个展开的Widget根据其子窗口的屏幕大小

Wired Firebase错误-[CLOUD_FIRESTORE/UNAvailable]该服务当前不可用

谷歌 map 在 flutter 应用程序中显示错误的当前位置

Flutter 使用扩展的 TextField 定位小部件

#Flutter/Riverpod - 使用 AsyncNotifier 时是否可以仅调用错误?

Flutter 应用程序在启动画面冻结(java.lang.RuntimeException:无法启动活动 ComponentInfo)

访问 AsyncSnapshot 中的嵌套属性

如何在 flutter 中创建渐变按钮

为什么 Flutter riverpod 直接分配不起作用但方法可以

有任何方法可以在应用程序移动背景恢复时显示 appopenAd