web-dev-qa-db-ja.com

タイプ 'int'はDartのタイプ 'String'エラーのサブタイプではありません

Printステートメントもそれより下のものも実行されず、エラーメッセージはvar timeで始まる最後の行の問題を示しています。 earthquakesがgrowableListであることも確認しました。つまり、earthquakes[0]は問題なく実行されるはずですが、そうではありません...何が間違っていますか?質問にさらに説明が必要な場合はお知らせください。提供します。 gif へのリンクエラーの- code へのリンクGitHub

私のコードの問題のある部分は次のとおりです。 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));
}
5
ThinkDigital
title: new Text(time ?? "Empty"),

あるべき

title: new Text(time != null ? '$time' : "Empty"),

または

title: new Text('${time ?? "Empty"}'),
6

スニペットの次の行のコードは次のとおりです。

title: new Text(time ?? "Empty"),

一方、実際には次のように見えるはずです。

title: new Text(time?.toString() ?? "Empty"),
0
Baig

エラーが発生していません。何を言ったらいいかわかりません...

0
scottstoll2017