I have 2 JSON file:
country.json
[
{
"countryName": "United States",
"countryContinent": "North America"
},
{
"countryName": "Germany",
"countryContinent": "Europe"
},
{
"countryName": "United Kingdom",
"countryContinent": "Europe"
}
]
continent.json
[
{
"continentName": "North America",
"continentCountry": [
"Canada",
"Mexico",
"Cuba"
],
"continentArea": 24790000,
"continentFlag": [
"https://www.countryflags.io/ca/shiny/64.png",
"https://www.countryflags.io/mx/shiny/64.png",
"https://www.countryflags.io/cu/shiny/64.png"
]
},
{
"continentName": "Europe",
"continentCountry": [
"Denmark",
"Finland",
"France"
],
"continentArea": 10180000,
"continentFlag": [
"https://www.countryflags.io/dk/shiny/64.png",
"https://www.countryflags.io/fi/shiny/64.png",
"https://www.countryflags.io/fr/shiny/64.png"
]
}
]
I want to build a list based on country.json, then for each value of countryContinent
that == value of continentName
=> show data of value continentCountry
from continent.json like this
So pls help me, this is main file:
import 'package:ask/model/continent_model.dart';
import 'package:ask/model/country_model.dart';
import 'package:ask/services/continent_services.dart';
import 'package:ask/services/country_service.dart';
import 'package:flutter/material.dart';
class Demo2 extends StatefulWidget {
Demo2() : super();
@override
_Demo2State createState() => _Demo2State();
}
class _Demo2State extends State<Demo2> {
List<Country> _country = [];
List<Continent> _continent = [];
@override
void initState() {
super.initState();
CountryServices.getCountry().then((countries) {
setState(() {
_country = countries;
});
});
ContinentServices.getContinent().then((continents) {
setState(() {
_continent = continents;
});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Demo 2')),
body: Column(
children: <Widget>[
for (Country country in _country)
Row(
children: <Widget>[
Expanded(child: Text(country.countryName)),
Expanded(child: Text(country.countryContinent)),
Expanded(child: Text('')), // How to show data of continentCountry
],
)
],
));
}
}
EDIT 2:
To avoid creating another post, I extend the following question:
in continent.json, there is more data about continentCountry
("Greenland"; "Panama"; "Jamaica") that matches the value of continentName
("North America") like this:
continent.json (edit 2)
[
{
"continentName": "North America",
"continentArea": "Area1",
"continentCountry": [
"Canada",
"Mexico",
"Cuba"
],
"continentFlag": [
"https://www.countryflags.io/ca/shiny/64.png",
"https://www.countryflags.io/mx/shiny/64.png",
"https://www.countryflags.io/cu/shiny/64.png"
]
},
{
"continentName": "North America",
"continentArea": "Area2",
"continentCountry": [
"Greenland",
"Panama",
"Jamaica"
],
"continentFlag": [
"https://www.countryflags.io/gl/shiny/64.png",
"https://www.countryflags.io/pa/shiny/64.png",
"https://www.countryflags.io/jm/shiny/64.png"
]
},
{
"continentName": "Europe",
"continentArea": "Area3",
"continentCountry": [
"Denmark",
"Finland",
"France"
],
"continentFlag": [
"https://www.countryflags.io/dk/shiny/64.png",
"https://www.countryflags.io/fi/shiny/64.png",
"https://www.countryflags.io/fr/shiny/64.png"
]
},
{
"continentName": "Asia",
"continentArea": "Area4",
"continentCountry": [
"Japan"
],
"continentFlag": [
"https://www.countryflags.io/jp/shiny/64.png"
]
}
]
so I want to display all of the continentCountry
of "North America" as follows:
Pls help