hello
voila je démarre flutter , en testant les Requête http , j'utilise les méthodes asynchrone et j'ai du mal a comprendre le retour des valeur
j'exécute ma fonction "Gettemp" dans "initstate" et je souhaiterais que la valeur retourner par "gettemp" soit affecter a "_temp"
en gros _temp = GetTemp();
comment dois faire SVP ?
Merci d'avance bonne soirée
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; class row2Screen extends StatefulWidget { const row2Screen({Key? key}) : super(key: key); _row2Widget createState() => _row2Widget(); } class _row2Widget extends State<row2Screen> { String _temp = ''; @override void initState() { super.initState(); GetTemp(); } Widget build(BuildContext context) { return Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ Text("La Température de la chambre Seb Fab est $_temp", style: TextStyle(fontSize: 15)) ], ); } } Future<String> GetTemp() async { var url = Uri.parse( 'http://xxxxxxxx'); // Await the http get response, then decode the json-formatted response. final response = await http.get(url); return response.body; }
Partager