1
0
mirror of https://github.com/nisrulz/flutter-examples.git synced 2025-11-08 20:50:04 +00:00

Added covid-19 example app and Updated the readme (#73)

This commit is contained in:
Mohammed Mehdi
2021-07-26 00:26:58 +05:30
committed by GitHub
parent 48f14caf15
commit 3eaedb619c
72 changed files with 2166 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
import '../screens/home.dart';
import '../screens/countrylist.dart';
import 'package:flutter/material.dart';
class DrawerWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Drawer(
child: ListView(
// Important: Remove any padding from the ListView.
padding: EdgeInsets.zero,
children: <Widget>[
Container(
child: Image.asset('assets/virus.gif'),
),
ListTile(
leading: CircleAvatar(
child: Image.asset("assets/logo.png"),
),
title: Text('Home'),
onTap: () {
Navigator.pushReplacement(
context, MaterialPageRoute(builder: (context) => Home()));
},
),
ListTile(
leading: CircleAvatar(
child: Image.asset("assets/logo.png"),
),
title: Text('Affected Countries'),
onTap: () {
Navigator.pushReplacement(context,
MaterialPageRoute(builder: (context) => CountryList()));
},
),
],
),
);
}
}

View File

@@ -0,0 +1,143 @@
import 'package:flutter/material.dart';
import 'package:folding_cell/folding_cell.dart';
import 'package:number_display/number_display.dart';
// To display data in a width-limited component
// Eg: converts 2,000,000 to 2M
String updateNumberDisplay(String number) {
final display = createDisplay(length: 4);
// we are converting number to an integer because it is a string
// and display expects an integer
return display(int.parse(number));
}
// the front widget for the foldable cell(when cell is collapsed)
Widget buildFrontWidget(
BuildContext context, String flagUrl, String country, String cases) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
children: <Widget>[
Container(
child: Image.network(
flagUrl,
width: MediaQuery.of(context).size.width * 0.2,
fit: BoxFit.cover,
)),
SizedBox(
width: 20.0,
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"Country: $country",
),
Text("Total Cases: ${updateNumberDisplay(cases)}"),
],
),
),
],
),
);
}
// the inner top widget for the foldable cell(when cell is expanded)
Widget buildInnerTopWidget(String country, String todayCases, String deaths,
String todayDeaths, String recovered, String critical, String cpm) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
color: Color(0xfff44e3f),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Text(
country,
style: TextStyle(fontSize: 20.0),
),
SizedBox(
height: 10.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"Today Cases: ${updateNumberDisplay(todayCases)}",
style: TextStyle(fontSize: 18.0),
),
Text(
"Deaths: ${updateNumberDisplay(deaths)}",
style: TextStyle(fontSize: 18.0),
),
Text(
"Cases/Million: ${updateNumberDisplay(cpm)}",
style: TextStyle(fontSize: 18.0),
),
],
),
SizedBox(
width: 10.0,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"Recovered: ${updateNumberDisplay(recovered)}",
style: TextStyle(fontSize: 18.0),
),
Text(
"Today Deaths: ${updateNumberDisplay(todayDeaths)}",
style: TextStyle(fontSize: 18.0),
),
Text(
"Critical: ${updateNumberDisplay(critical)}",
style: TextStyle(fontSize: 18.0),
),
],
),
],
),
],
),
);
}
// the inner bottom widget for the foldable cell(when cell is expanded)
Widget buildInnerBottomWidget(String cases) {
return Builder(builder: (context) {
return Container(
color: Color(0xfff44e3f),
padding: EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
Expanded(
child: Text(
"Total Cases:\n${updateNumberDisplay(cases)}",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20.0,
),
)),
FlatButton(
onPressed: () {
SimpleFoldingCellState foldingCellState =
context.findAncestorStateOfType();
foldingCellState?.toggleFold();
},
child: Text(
"Close",
),
color: Colors.black,
shape: StadiumBorder(),
splashColor: Colors.white.withOpacity(0.5),
),
],
),
);
});
}

View File

@@ -0,0 +1,51 @@
import 'package:flutter/material.dart';
import 'package:bezier_chart/bezier_chart.dart';
// Widget that will build the graph
Widget buildGraph(
BuildContext context, List<Map<String, dynamic>> datesAndValues) {
// Data is avalaible from a particular date and we are getting that here
final fromDate = datesAndValues[0]['date'];
// Data is avalaible until a particular date and we are getting that here
final toDate = datesAndValues.last['date'];
// Add dates and values corresponding to those dates
// in a list
List<DataPoint<DateTime>> dataPoints = [];
for (final dateAndValue in datesAndValues) {
dataPoints.add(DataPoint<DateTime>(
value: double.parse(dateAndValue['value'].toString()),
xAxis: dateAndValue['date']));
}
return Center(
child: Container(
decoration: BoxDecoration(
color: Colors.red,
),
height: MediaQuery.of(context).size.height / 2,
width: MediaQuery.of(context).size.width,
child: BezierChart(
fromDate: fromDate,
bezierChartScale: BezierChartScale.WEEKLY,
toDate: toDate,
selectedDate: toDate,
series: [
BezierLine(
data: dataPoints,
),
],
config: BezierChartConfig(
physics: BouncingScrollPhysics(),
verticalIndicatorStrokeWidth: 3.0,
verticalIndicatorColor: Colors.black26,
showVerticalIndicator: true,
verticalIndicatorFixedPosition: false,
backgroundColor: Colors.transparent,
footerHeight: 30.0,
),
),
),
);
}

View File

@@ -0,0 +1,31 @@
import 'package:flutter/material.dart';
// this is the rounded rectangle card widget that appears on the homescreen
Widget infoCard(BuildContext context, String title, String number) {
return Card(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
title,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: MediaQuery.of(context).size.height * 0.03,
),
),
SizedBox(
height: 5.0,
),
Text(
number,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20.0,
),
),
],
),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(40.0)),
color: Color(0xfff44e3f),
);
}