Когда я хочу, чтобы мои изображения отображались на моих карточках (переменное изображение 2/3/4/5/6/7), работала только основная картинка. Мой код получает данные из json ссылки , и с помощью переменной стиля погоды я могу с условием заполнить переменные image1 (2/3/4/5/6/7), но только image1 работает Это мой код:
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:io';
import 'dart:core';
void main() => runApp(new MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String temperature1;
String humid1;
String ressentie1;
String air1;
String weatherstyle1;
String image1;
String date1;
String temperature2;
String humid2;
String weatherstyle2;
String image2;
String date2;
String temperature3;
String humid3;
String weatherstyle3;
String image3;
String date3;
String temperature4;
String humid4;
String weatherstyle4;
String image4;
String date4;
String temperature5;
String humid5;
String weatherstyle5;
String image5;
String date5;
String temperature6;
String humid6;
String weatherstyle6;
String image6;
String date6;
String temperature7;
String humid7;
String weatherstyle7;
String image7;
String date7;
bool isData = false;
_MyAppState(
{this.temperature1,
this.humid1,
this.ressentie1,
this.air1,
this.weatherstyle1,
this.image1,
this.date1,
this.temperature2,
this.humid2,
this.weatherstyle2,
this.image2,
this.date2,
this.temperature3,
this.humid3,
this.weatherstyle3,
this.image3,
this.date3,
this.temperature4,
this.humid4,
this.weatherstyle4,
this.image4,
this.date4,
this.temperature5,
this.humid5,
this.weatherstyle5,
this.image5,
this.date5,
this.temperature6,
this.humid6,
this.weatherstyle6,
this.image6,
this.date6,
this.temperature7,
this.humid7,
this.weatherstyle7,
this.image7,
this.date7});
recupJSON() async {
var gethttp = await http.get(
"https://raw.githubusercontent.com/w-station/pull/master/exemple.json",
headers: {"Accept": "application/json"},
);
if (gethttp.statusCode == 200) {
String responseBody = gethttp.body;
var responseJSON = json.decode(responseBody);
temperature1 = responseJSON['temperature1'];
temperature2 = responseJSON['temperature2'];
temperature3 = responseJSON['temperature3'];
temperature4 = responseJSON['temperature4'];
temperature5 = responseJSON['temperature5'];
temperature6 = responseJSON['temperature6'];
temperature7 = responseJSON['temperature7'];
humid1 = responseJSON['humid1'];
humid2 = responseJSON['humid2'];
humid3 = responseJSON['humid3'];
humid4 = responseJSON['humid4'];
humid5 = responseJSON['humid5'];
humid6 = responseJSON['humid6'];
humid7 = responseJSON['humid7'];
ressentie1 = responseJSON['ressentie1'];
air1 = responseJSON['air1'];
weatherstyle1 = responseJSON['weatherstyle1'];
weatherstyle2 = responseJSON['weatherstyle2'];
weatherstyle3 = responseJSON['weatherstyle3'];
weatherstyle4 = responseJSON['weatherstyle4'];
weatherstyle5 = responseJSON['weatherstyle5'];
weatherstyle6 = responseJSON['weatherstyle6'];
weatherstyle7 = responseJSON['weatherstyle7'];
date1 = responseJSON['date1'];
date2 = responseJSON['date2'];
date3 = responseJSON['date3'];
date4 = responseJSON['date4'];
date5 = responseJSON['date5'];
date6 = responseJSON['date6'];
date7 = responseJSON['date7'];
isData = true;
if (weatherstyle1 == "Ensoleillé") {
image1 = "images/big/Ensoleillé.png";
} else if (weatherstyle1 == "Éclaircie") {
image1 = "images/big/Éclaircie.png";
} else if (weatherstyle1 == "Pluvieux") {
image1 = "images/big/Pluvieux.png";
} else if (weatherstyle1 == "Orage") {
image1 = "images/big/Orage.png";
} else if (weatherstyle1 == "Nuageux") {
image1 = "images/big/Nuageux.png";
} else if (weatherstyle1 == "Canicule") {
image1 = "images/big/Canicule.png";
} else if (weatherstyle1 == "Neige") {
image2 = "images/big/Neige.png";
}
else if (weatherstyle2 == "Ensoleillé") {
image2 = "images/small/Ensoleillé.png";
} else if (weatherstyle3 == "Ensoleillé") {
image3 = "images/small/Ensoleillé.png";
} else if (weatherstyle4 == "Ensoleillé") {
image4 = "images/small/Ensoleillé.png";
} else if (weatherstyle5 == "Ensoleillé") {
image5 = "images/small/Ensoleillé.png";
} else if (weatherstyle6 == "Ensoleillé") {
image6 = "images/small/Ensoleillé.png";
} else if (weatherstyle7 == "Ensoleillé") {
image7 = "images/small/Ensoleillé.png";
}
else if (weatherstyle2 == "Éclaircie") {
image2 = "images/small/Éclaircie.png";
} else if (weatherstyle3 == "Éclaircie") {
image3 = "images/small/Éclaircie.png";
} else if (weatherstyle4 == "Éclaircie") {
image4 = "images/small/Éclaircie.png";
} else if (weatherstyle5 == "Éclaircie") {
image5 = "images/small/Éclaircie.png";
} else if (weatherstyle6 == "Éclaircie") {
image6 = "images/small/Éclaircie.png";
} else if (weatherstyle7 == "Éclaircie") {
image7 = "images/small/Éclaircie.png";
}
else if (weatherstyle2 == "Pluvieux") {
image2 = "images/small/Pluvieux.png";
} else if (weatherstyle3 == "Pluvieux") {
image3 = "images/small/Pluvieux.png";
} else if (weatherstyle4 == "Pluvieux") {
image4 = "images/small/Pluvieux.png";
} else if (weatherstyle5 == "Pluvieux") {
image5 = "images/small/Pluvieux.png";
} else if (weatherstyle6 == "Pluvieux") {
image6 = "images/small/Pluvieux.png";
} else if (weatherstyle7 == "Pluvieux") {
image7 = "images/small/Pluvieux.png";
}
else if (weatherstyle2 == "Orage") {
image2 = "images/small/Orage.png";
} else if (weatherstyle3 == "Orage") {
image3 = "images/small/Orage.png";
} else if (weatherstyle4 == "Orage") {
image4 = "images/small/Orage.png";
} else if (weatherstyle5 == "Orage") {
image5 = "images/small/Orage.png";
} else if (weatherstyle6 == "Orage") {
image6 = "images/small/Orage.png";
} else if (weatherstyle7 == "Orage") {
image7 = "images/small/Orage.png";
}
else if (weatherstyle2 == "Nuageux") {
image2 = "images/small/Nuageux.png";
} else if (weatherstyle3 == "Nuageux") {
image3 = "images/small/Nuageux.png";
} else if (weatherstyle4 == "Nuageux") {
image4 = "images/small/Nuageux.png";
} else if (weatherstyle5 == "Nuageux") {
image5 = "images/small/Nuageux.png";
} else if (weatherstyle6 == "Nuageux") {
image6 = "images/small/Nuageux.png";
} else if (weatherstyle7 == "Nuageux") {
image7 = "images/small/Nuageux.png";
}
else if (weatherstyle2 == "Canicule") {
image2 = "images/small/Canicule.png";
} else if (weatherstyle3 == "Canicule") {
image3 = "images/small/Canicule.png";
} else if (weatherstyle4 == "Canicule") {
image4 = "images/small/Canicule.png";
} else if (weatherstyle5 == "Canicule") {
image5 = "images/small/Canicule.png";
} else if (weatherstyle6 == "Canicule") {
image6 = "images/small/Canicule.png";
} else if (weatherstyle7 == "Canicule") {
image7 = "images/small/Canicule.png";
}
else if (weatherstyle2 == "Neige") {
image2 = "images/small/Neige.png";
} else if (weatherstyle3 == "Neige") {
image3 = "images/small/Neige.png";
} else if (weatherstyle4 == "Neige") {
image4 = "images/small/Neige.png";
} else if (weatherstyle5 == "Neige") {
image5 = "images/small/Neige.png";
} else if (weatherstyle6 == "Neige") {
image6 = "images/small/Neige.png";
} else if (weatherstyle7 == "Neige") {
image7 = "images/small/Neige.png";
}
setState(() {
print('UI Updated');
});
} else {
print('Something went wrong. \nResponse Code : ${gethttp.statusCode}');
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['temperature1'] = this.temperature1;
data['humid1'] = this.humid1;
data['ressentie1'] = this.ressentie1;
data['air1'] = this.air1;
data['weatherstyle1'] = this.weatherstyle1;
data['date1'] = this.date1;
data['temperature2'] = this.temperature2;
data['humid2'] = this.humid2;
data['weatherstyle2'] = this.weatherstyle2;
data['date2'] = this.date2;
data['temperature3'] = this.temperature3;
data['humid3'] = this.humid3;
data['weatherstyle3'] = this.weatherstyle3;
data['date3'] = this.date3;
data['temperature4'] = this.temperature4;
data['humid4'] = this.humid4;
data['weatherstyle4'] = this.weatherstyle4;
data['date4'] = this.date4;
data['temperature5'] = this.temperature5;
data['humid5'] = this.humid5;
data['weatherstyle5'] = this.weatherstyle5;
data['date5'] = this.date5;
data['temperature6'] = this.temperature6;
data['humid6'] = this.humid6;
data['weatherstyle6'] = this.weatherstyle6;
data['date6'] = this.date6;
data['temperature7'] = this.temperature7;
data['humid7'] = this.humid7;
data['weatherstyle7'] = this.weatherstyle7;
data['date7'] = this.date7;
return data;
}
@override
void initState() {
super.initState();
recupJSON();
}
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Color(0xffb403278),
appBar: AppBar(
leading: IconButton(
icon: Icon(Icons.arrow_back_ios),
onPressed: () => exit(0),
),
centerTitle: true,
backgroundColor: Color(0xffb403278),
title: Text('Wstation'),
actions: <Widget>[
IconButton(
icon: Icon(Icons.refresh),
onPressed: () {
recupJSON();
}),
],
),
body: Center(
child:
Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
Text(date1,
style: new TextStyle(
color: Colors.white, fontSize: 26)),
Text("Maison",
style: new TextStyle(
color: Colors.green, fontSize: 42.0)),
Text((temperature1 + "°C " + humid1 + "% "),
style: new TextStyle(
color: Colors.purple, fontSize: 25)),
Image.asset(image1),
],
),
),
],
),
),
SafeArea(
child: Container(
margin: EdgeInsets.symmetric(vertical: 20.0),
height: 215,
child: ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
Container(
width: 135.0,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text((weatherstyle2),
style: new TextStyle(
color: Colors.black, fontSize: 24.0)),
Text((temperature2 + "°C " + humid2 + "%"),
style: new TextStyle(color: Colors.black)),
Image.asset(image2),
Text((date2),
style: new TextStyle(color: Colors.black)),
],
))),
Container(
width: 135.0,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text((weatherstyle3),
style: new TextStyle(
color: Colors.black, fontSize: 24.0)),
Text((temperature3 + "°C " + humid3 + "%"),
style: new TextStyle(color: Colors.black)),
Image.asset(image3),
Text((date3),
style: new TextStyle(color: Colors.black)),
],
))),
Container(
width: 135.0,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text((weatherstyle4),
style: new TextStyle(
color: Colors.black, fontSize: 24.0)),
Text((temperature4 + "°C " + humid4 + "%"),
style: new TextStyle(color: Colors.black)),
Image.asset(image4),
Text((date4),
style: new TextStyle(color: Colors.black)),
],
))),
Container(
width: 135.0,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text((weatherstyle5),
style: new TextStyle(
color: Colors.black, fontSize: 24.0)),
Text((temperature5 + "°C " + humid5 + "%"),
style: new TextStyle(color: Colors.black)),
Image.asset(image5),
Text((date5),
style: new TextStyle(color: Colors.black)),
],
))),
Container(
width: 135.0,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text((weatherstyle6),
style: new TextStyle(
color: Colors.black, fontSize: 24.0)),
Text((temperature6 + "°C " + humid6 + "%"),
style: new TextStyle(color: Colors.black)),
Image.asset(image6),
Text((date6),
style: new TextStyle(color: Colors.black)),
],
))),
Container(
width: 135.0,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text((weatherstyle7),
style: new TextStyle(
color: Colors.black, fontSize: 24.0)),
Text((temperature7 + "°C " + humid7 + "%"),
style: new TextStyle(color: Colors.black)),
Image.asset(image7),
Text((date7),
style: new TextStyle(color: Colors.black)),
],
))),
],
),
))
]))));
}
}
Пожалуйста, помогите мне, я новичок в трепете и дротике