Skip to content

Commit

Permalink
Finished the WORLDWIDE widget, with API data.
Browse files Browse the repository at this point in the history
  • Loading branch information
MateusPedrosoSilva committed May 14, 2020
1 parent a0ec7b8 commit 0d0b32a
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 26 deletions.
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
# covidapp
# Covid Tracker

A Covid tracker app
A Covid-19 tracker app made with Flutter.

## Getting Started

This project is a starting point for a Flutter application.
This app is a case for study API consuming with Flutter.

A few resources to get you started if this is your first Flutter project:
Features:
- Show Worldwide data;

- [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook)

For help getting started with Flutter, view our
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
Data get from: [https://corona.lmao.ninja](https://corona.lmao.ninja)
3 changes: 1 addition & 2 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 51;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -70,7 +70,6 @@
51924B459DBBFD166CC03FE5 /* Pods-Runner.release.xcconfig */,
F0C3EEEE45CDF174FE64DDF5 /* Pods-Runner.profile.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
Expand Down
71 changes: 64 additions & 7 deletions lib/homepage.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
import 'dart:convert';

import 'package:covidapp/datasorce.dart';
import 'package:covidapp/panels/worldwidepanel.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
Map worldData;
fetchWorldwideData() async {
http.Response response = await http.get('https://corona.lmao.ninja/v2/all');
setState(() {
worldData = json.decode(response.body);
});
}

List countryData;
fetchCountryData() async {
http.Response response =
await http.get('https://corona.lmao.ninja/v2/countries');
setState(() {
countryData = json.decode(response.body);
});
}

@override
void initState() {
fetchWorldwideData();
fetchCountryData();
super.initState();
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down Expand Up @@ -38,15 +65,45 @@ class _HomePageState extends State<HomePage> {
vertical: 10.0,
horizontal: 10.0,
),
child: Text(
'WorldWide',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 22,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'WorldWide',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 22,
),
),
Container(
padding: EdgeInsets.all(10.0),
decoration: BoxDecoration(
color: primaryBlack,
borderRadius: BorderRadius.circular(15.0)),
child: Text(
'REGIONAL',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
)
],
),
),
WorldWidePanel(),
worldData == null
? CircularProgressIndicator()
: WorldWidePanel(
worldData: worldData,
),
Text(
'Most affected countries',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 22,
),
)
],
),
),
Expand Down
15 changes: 15 additions & 0 deletions lib/panels/mosteffectedcontries.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:flutter/material.dart';

class MostAffectedPanel extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
child: ListView.builder(
itemBuilder: (context, index) {
return Container();
},
itemCount: 5,
),
);
}
}
49 changes: 42 additions & 7 deletions lib/panels/worldwidepanel.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import 'package:flutter/material.dart';

class WorldWidePanel extends StatelessWidget {
final Map worldData;

const WorldWidePanel({Key key, this.worldData}) : super(key: key);

@override
Widget build(BuildContext context) {
return Container(
Expand All @@ -12,17 +16,46 @@ class WorldWidePanel extends StatelessWidget {
childAspectRatio: 2,
),
children: <Widget>[
StatusPanel(),
StatusPanel(),
StatusPanel(),
StatusPanel(),
StatusPanel(
title: 'CONFIRMED',
panelColor: Colors.red[100],
textColor: Colors.red,
count: worldData['cases'].toString(),
),
StatusPanel(
title: 'ACTIVE',
panelColor: Colors.blue[100],
textColor: Colors.blue[900],
count: worldData['active'].toString(),
),
StatusPanel(
title: 'RECOVERED',
panelColor: Colors.green[100],
textColor: Colors.green,
count: worldData['recovered'].toString(),
),
StatusPanel(
title: 'DEATHS',
panelColor: Colors.grey[400],
textColor: Colors.grey[900],
count: worldData['deaths'].toString(),
),
],
),
);
}
}

class StatusPanel extends StatelessWidget {
final Color panelColor;
final Color textColor;
final String title;
final String count;

const StatusPanel(
{Key key, this.panelColor, this.textColor, this.title, this.count})
: super(key: key);

@override
Widget build(BuildContext context) {
// Width of the device.
Expand All @@ -31,21 +64,23 @@ class StatusPanel extends StatelessWidget {
height: 80,
width: width / 2,
margin: EdgeInsets.all(10.0),
color: Colors.blue[100],
color: panelColor,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'CONFIRMED',
title,
style: TextStyle(
fontWeight: FontWeight.bold,
color: textColor,
fontSize: 16,
),
),
Text(
'1234',
count,
style: TextStyle(
fontWeight: FontWeight.bold,
color: textColor,
fontSize: 16,
),
),
Expand Down

0 comments on commit 0d0b32a

Please sign in to comment.