Commit 92e94b98 authored by GayaniPKarunaratne's avatar GayaniPKarunaratne

Done some parts in Connecting API

parent cc56f1b7
import 'package:covidefender/EAnalyzer/HospitalDetails.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'AddLocation.dart'; import 'AddLocation.dart';
...@@ -134,6 +135,26 @@ class EAnalyzerDash extends StatelessWidget { ...@@ -134,6 +135,26 @@ class EAnalyzerDash extends StatelessWidget {
], ],
) )
), ),
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8)),
elevation: 4,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FlatButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => HospitalDetails()),
);
},
child: Image.asset('lib/assets/images/search80.png'),
),
Text('Search Hospitals', style: TextStyle(fontSize: 20.0))
],
)
),
], ],
), ),
) )
......
import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http;
class HospitalDetails extends StatefulWidget {
HospitalDetails({Key key,this.title}) :super(key: key);
final String title;
@override
_HospitalDetailsState createState() => _HospitalDetailsState();
}
class _HospitalDetailsState extends State<HospitalDetails> {
//---------------------------------------------------------------------------------------------------------------------------------------
// Future<List<Hospital>> _getHospitals() async{
// var data = await http.get("https://www.hpb.health.gov.lk/api/get-current-statistical");
// var jsonData = json.decode(data.body);
// List<Hospital> hospitals = [];
// for(var hospital in jsonData["data"]){
// Hospital newHospital =Hospital(hospital["update_date_time"],hospital["local_new_cases"]);
// //, hospital["cumulative_local"], hospital["cumulative_foreign"], hospital["created_at"]
// hospitals.add(newHospital);
// }
// return hospitals;
// }
//---------------------------------------------------------------------------------------------------------------------------------------
Map data;
List userData;
Future getData() async{
http.Response response = await http.get("https://reqres.in/api/users?page=2");
data = json.decode(response.body);
setState(() {
userData = data["data"];
});
debugPrint(userData.toString());
}
@override
void initState() {
super.initState();
getData();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backwardsCompatibility: false,
backgroundColor: Color(0xFF1B5E20),
title: Text("Search Hospitals COVID-19 Details"),
),
body: ListView.builder(
itemCount: userData == null ? 0 : userData.length,
itemBuilder: (BuildContext context, int index) {
return Card(
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Row(
children: <Widget>[
CircleAvatar(
backgroundImage: NetworkImage(userData[index]["avatar"]) ,
),
Padding(
padding: const EdgeInsets.all(12.0),
child: Text("${userData[index]["first_name"]} ${userData[index]["last_name"]}",
style: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.w700,
),),
),
Text("${userData[index]["id"]}"),
Text("${userData[index]["email"]}"),
],
),
),
);
},
),
//-----------------------------------------------------------------------------------------------------------------------------------------
// body: Container(
// child: FutureBuilder(
// //future: _getHospitals(),
// builder: (BuildContext context, AsyncSnapshot snapshot){
// if (snapshot.data == null) {
// return Container(
// child: Center(
// child: Text("No data....."),
// ),
// );
// }else{
// return ListView.builder(
// itemCount: snapshot.data.lenght,
// itemBuilder: (BuildContext context, int index){
// return ListTile(
// title: Text(snapshot.data[index].updateDateTime),
// subtitle: Text(snapshot.data[index].localNewCases),
// );
// },
// );
// }
// },
// ),
// ),
//---------------------------------------------------------------------------------------------------------------------------------------
);
}
}
//-----------------------------------------Class Hospital--------------------------------------------------
class Hospital{
final String updateDateTime;
final String localNewCases;
// final String hospitalId;
// final String hospital;
// final String cumulativeLocal;
// final String cumulativeForeign;
// final String createdAt;
//Hospital(this.hospitalId,this.hospital,this.cumulativeLocal,this.cumulativeForeign,this.createdAt);
Hospital(this.updateDateTime,this.localNewCases);
}
\ No newline at end of file
...@@ -107,7 +107,7 @@ packages: ...@@ -107,7 +107,7 @@ packages:
name: cupertino_icons name: cupertino_icons
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.2" version: "1.0.3"
fake_async: fake_async:
dependency: transitive dependency: transitive
description: description:
...@@ -158,6 +158,13 @@ packages: ...@@ -158,6 +158,13 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
http:
dependency: "direct main"
description:
name: http
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.2"
http_parser: http_parser:
dependency: transitive dependency: transitive
description: description:
...@@ -220,14 +227,14 @@ packages: ...@@ -220,14 +227,14 @@ packages:
name: path_drawing name: path_drawing
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.5.0" version: "0.5.1"
path_parsing: path_parsing:
dependency: transitive dependency: transitive
description: description:
name: path_parsing name: path_parsing
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.2.0" version: "0.2.1"
pedantic: pedantic:
dependency: transitive dependency: transitive
description: description:
...@@ -344,7 +351,7 @@ packages: ...@@ -344,7 +351,7 @@ packages:
name: xml name: xml
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "5.1.0" version: "5.1.2"
sdks: sdks:
dart: ">=2.12.0 <3.0.0" dart: ">=2.12.0 <3.0.0"
flutter: ">=1.24.0-7.0" flutter: ">=1.24.0-7.0"
...@@ -38,6 +38,7 @@ dependencies: ...@@ -38,6 +38,7 @@ dependencies:
# The following adds the Cupertino Icons font to your application. # The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons. # Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2 cupertino_icons: ^1.0.2
http: ^0.12.2
#add dependencies for heart rate module #add dependencies for heart rate module
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment