Created
April 28, 2021 15:46
-
-
Save malibayram/4877a3f26259e03224bd9d76826823d8 to your computer and use it in GitHub Desktop.
Mustafa Yıldız tarafından 28 Nisan 2021'de Discord'ta sorduğu soruya cevap olarak oluşturuldu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Covid { | |
| String? patients; | |
| String? totalPatients; | |
| String? deaths; | |
| String? totalDeaths; | |
| String? recovered; | |
| String? totalRecovered; | |
| String? totalIntubated; | |
| String? totalIntensiveCare; | |
| String? tests; | |
| String? totalTests; | |
| String? date; | |
| String? critical; | |
| String? pneumoniaPercent; | |
| Covid({ | |
| this.patients, | |
| this.totalPatients, | |
| this.deaths, | |
| this.totalDeaths, | |
| this.recovered, | |
| this.totalRecovered, | |
| this.totalIntubated, | |
| this.totalIntensiveCare, | |
| this.tests, | |
| this.totalTests, | |
| this.date, | |
| this.critical, | |
| this.pneumoniaPercent, | |
| }); | |
| Covid.fromJson(Map? json) { | |
| patients = json!['patients']; | |
| totalPatients = json['totalPatients']; | |
| deaths = json['deaths']; | |
| totalDeaths = json['totalDeaths']; | |
| recovered = json['recovered']; | |
| totalRecovered = json['totalRecovered']; | |
| totalIntubated = json['totalIntubated']; | |
| totalIntensiveCare = json['totalIntensiveCare']; | |
| tests = json['tests']; | |
| totalTests = json['totalTests']; | |
| date = json['date']; | |
| critical = json['critical']; | |
| pneumoniaPercent = json['pneumoniaPercent']; | |
| } | |
| Map<String, dynamic> toJson() { | |
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |
| data['patients'] = this.patients; | |
| data['totalPatients'] = this.totalPatients; | |
| data['deaths'] = this.deaths; | |
| data['totalDeaths'] = this.totalDeaths; | |
| data['recovered'] = this.recovered; | |
| data['totalRecovered'] = this.totalRecovered; | |
| data['totalIntubated'] = this.totalIntubated; | |
| data['totalIntensiveCare'] = this.totalIntensiveCare; | |
| data['tests'] = this.tests; | |
| data['totalTests'] = this.totalTests; | |
| data['date'] = this.date; | |
| data['critical'] = this.critical; | |
| data['pneumoniaPercent'] = this.pneumoniaPercent; | |
| return data; | |
| } | |
| } | |
| class MyHomePage extends StatefulWidget { | |
| MyHomePage({Key? key, this.title}) : super(key: key); | |
| final String? title; | |
| @override | |
| _MyHomePageState createState() => _MyHomePageState(); | |
| } | |
| class _MyHomePageState extends State<MyHomePage> { | |
| Future<List<Covid>> _verial() async { | |
| String adres = | |
| "https://raw.githubusercontent.com/ozanerturk/covid19-turkey-api/master/dataset/timeline.json"; | |
| try { | |
| Response cevap = await get(Uri.parse(adres)); | |
| await Future.delayed(Duration(seconds: 2)); | |
| if (cevap.statusCode == 200) { | |
| Map gelenCevap = jsonDecode(cevap.body); | |
| List<Covid> covidler = []; | |
| for (String gelenCevapMapKey in gelenCevap.keys) { | |
| Covid covid = Covid.fromJson(gelenCevap[gelenCevapMapKey]); | |
| covidler.add(covid); | |
| } | |
| return covidler; | |
| } else { | |
| print("Bağlantıdan gelen cevapta sorun oluştu"); | |
| } | |
| } catch (e) { | |
| print("hata oluştu"); | |
| print(e); | |
| } | |
| return []; | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| appBar: AppBar( | |
| title: Text(widget.title!), | |
| ), | |
| body: FutureBuilder<List<Covid>>( | |
| future: _verial(), | |
| builder: (ctx, snapshot) { | |
| if (snapshot.hasData) | |
| return ListView.builder( | |
| itemCount: snapshot.data!.length, | |
| itemBuilder: (ctxListView, index) { | |
| return Card( | |
| child: Text(snapshot.data![index].date!), | |
| ); | |
| }, | |
| ); | |
| return Center(child: CircularProgressIndicator()); | |
| }, | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment