Skip to content

Instantly share code, notes, and snippets.

View Classy-Bear's full-sized avatar
🎩
Doing magic, speaking to goblins

David Acevedo Classy-Bear

🎩
Doing magic, speaking to goblins
  • Scotiabank
  • Dominican Republic
  • 22:38 (UTC -04:00)
View GitHub Profile
@override
void initState() {
super.initState();
connectivity = Connectivity();
subscription =
connectivity.onConnectivityChanged.listen((ConnectivityResult result) {
if (result == ConnectivityResult.wifi || result == ConnectivityResult.mobile) {
setState(() {});
}
});
import 'package:connectivity/connectivity.dart';
...
Connectivity connectivity;
StreamSubscription<ConnectivityResult> subscription;
FutureBuilder(
future: getData(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasError) {
return Center(child: Text('Error'));
}
if (snapshot.connectionState == ConnectionState.done) {
var mydata = snapshot.data;
return Center(child: Text('${mydata['data'][0]['email']}'));
} else {
FutureBuilder(
future: getData(),
builder: (BuildContext context, AsyncSnapshot snapshot) {}
)
Future getData() async {
http.Response response = await http.get("https://reqres.in/api/users");
if (response.statusCode == HttpStatus.ok) {
var result = jsonDecode(response.body);
return result;
}
}
import 'package:http/http.dart' as http;
...
FutureBuilder(
builder: (BuildContext context, AsyncSnapshot snapshot) {}
)