У меня есть задание, мне нужно показать значение из Apis, а затем при нажатии на поднятую кнопку появится следующее значение
Вот мой код
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
var _questions = new List<Questions>();
_getQuestions() {
API.getUsers().then((response) {
setState(() {
Iterable list = json.decode(response.body);
print(list);
print(list);
_questions = list.map((model) => Questions.fromJson(model)).toList();
print(_questions);
});
});
}
initState() {
super.initState();
_getQuestions();
}
final PrimaryColor = const Color(0xff404040);
final PreferredSizeWidget appBar = AppBar(
centerTitle: true,
title: Text(
'Would you Rather',
style: TextStyle(fontFamily: 'FredokaOne'),
),
backgroundColor: PrimaryColor,
);
double stackHeight = (MediaQuery.of(context).size.height -
appBar.preferredSize.height -
MediaQuery.of(context).padding.top);
double stackWidth = MediaQuery.of(context).size.width;
return Scaffold(
backgroundColor: Color(0xff404040),
appBar: appBar,
body: Column(
children: <Widget>[
Container(
child: Text('need to show value here'),
),
RaisedButton(
onPressed: on this press i need to change value,
child: Text('next'),
)
],
));
}
}
Как видите в _questions
здесь массив в формате json, мне нужно распечатать значение, и при нажатии будет отображаться следующее значение.
Получение данных из api выглядит следующим образом
[
{
"rather": "Tea",
"would": "Coffe",
"wouldClick": 15,
"ratherClick": 12
},
{
"rather": "Oil",
"would": "Soap",
"wouldClick": 50,
"ratherClick": 12
},
{
"rather": "Soap",
"would": "Shaving Cream",
"wouldClick": 15,
"ratherClick": 12
}
]
Мне нужно для отображения значения rather
из данных и при щелчке мыши необходимо изменить другое значение rather