import 'dart:async'; import 'dart:convert'; import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:http/http.dart' as http; Future fetchOficina() async { final response = await http.get('https://ada.uprrp.edu/~oniel.mendez2/json/getOficinas.php'); if (response.statusCode == 200) { return Oficina.fromJson(jsonDecode(response.body)); } else { throw Exception('Failed to load album'); } } class Oficina { String id; String name; Oficina({this.id, this.name}); factory Oficina.fromJson(Map json) { return Oficina ( id :json['id'], name: json['name'], ); } } Future main() async { runApp(album()); } class album extends StatefulWidget { album({Key key}) : super(key: key); @override _MyAppState2 createState() => _MyAppState2(); } class _MyAppState2 extends State { Future futureOficina; @override void initState() { super.initState(); futureOficina = fetchOficina(); } @override Widget build(BuildContext context) { return MaterialApp( title: 'Fetch Data Example', theme: ThemeData( primarySwatch: Colors.blue, ), home: Scaffold( appBar: AppBar( title: Text('Fetch Data Example'), ), body: Center( child: FutureBuilder( future: futureOficina, builder: (context, snapshot) { if (snapshot.hasData) { return Text(snapshot.data.name); } else if (snapshot.hasError) { return Text("${snapshot.error}"); } // By default, show a loading spinner. return CircularProgressIndicator(); }, ), ), ), ); } }