Я получаю данные json с json -generator.com и анализирую их, чтобы создать список компаний в приведенном ниже коде. Когда я печатаю переменную JsonData, я вижу данные, но snapshot.data имеет значение null. вот мой код
import 'package:flutter/material.dart';
import './Object.dart';
import 'dart:async';
import 'package:http/http.dart' as http;
import 'UI_Styles/Company_Card_Style.dart';
import 'dart:convert';
class Companies extends StatefulWidget {
@override
_CompaniesState createState() => _CompaniesState();
}
class _CompaniesState extends State<Companies> {
Future<List<Company>> _getCompanies() async {
var data = await http.get("http://www.json-generator.com/api/json/get/bUYmnsimgi?indent=2");
var jsonData = json.decode(data.body);
List<Company> companies = [];
for (var c in jsonData) {
Company company = Company(
c["name"],
c["opportunites"],
c["address"],
c["city"],
c["state"],
c["country"],
c["zipcode"],
c["phone"],
c["timezone"],
c["pipelineRevenue"],
c["revenueAchieved"],
c["tags"]);
companies.add(company);
}
return companies;
}
@override
Widget build(BuildContext context) {
return Container(
child: FutureBuilder(
future: _getCompanies(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasData) {
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, int index) {
return CompanyCardStyle(company: snapshot.data[index]);
});
} else {
return Center(
child: CircularProgressIndicator(),
);
}
}));
}
}
Вот объект моей компании
class Company {
String name;
String address;
int opportunities;
int pipelineRevenue;
int revenueAchieved;
String city;
String state;
String country;
int zipcode;
double phone;
String timezone;
String tags;
Company(
this.name,
this.address,
this.opportunities,
this.pipelineRevenue,
this.revenueAchieved,
this.city,
this.state,
this.country,
this.zipcode,
this.phone,
this.timezone,
this.tags);
}
Я думаю, что есть проблема с l oop, но я не могу понять, что не так Я новичок для такого анализа данных.